/* @(#)GSOrderDetailDAO.java
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li     2006-2-15    新增
 *   Jenny Li     2006-3-7   添加方法queryUncommitOrderInfoForNonFlatProv
 *   Jenny Li     2006-3-7   修改方法queryAllAuthoriseOrders，增加查询条件：供应商为交易平台供应商
 *   Jenny Li     2006-3-15  添加方法queryOrderDetailByOpt
 *   Jenny Li     2006-3-16  添加方法updateDetailStatusByOrderId
 *   Jenny Li     2006-3-18  添加方法queryOrderDetail
 *   Jenny Li     2006-4-17  添加方法insertOrderDetailFromTemp
 *   Jenny Li     2006-4-26  添加方法queryUnBalanceDetail
 *   Jenny Li     2006-4-27  添加方法EmergencyOrderQueryDetail，insertOrderDetailFromTemp
 *   Jenny Li     2006-5-16  添加方法queryUnBalanceDetail，querySignedDetail，querySignedDetailCount，
 *                              getSignedOrgDetailSql，getSignedProviderDetailSql，queryDetailAssociatedBalanced
 *                              queryDetailAssociatedBalancedCount，getBalancedOrgDetailSql，
 *                              getBalancedProviderDetailSql，updateDetailBalanced，querySignedDetail
 *   Jenny Li     2006-5-23	 修改方法getSqlForOrderSubmitOfNonFlat查询非网上订单的条件
 *   Jenny Li     2006-5-24  添加方法queryHistoryOrderDetailCount,queryHistoryOrderDetail
 *                           修改方法getOrderDtlSqlForStatusTrace可用于查询历史订单
 *   Jenny Li     2006-5-27  添加方法updateDetailAsOrdering
 *   Jenny Li     2006-6-1   修改方法getOrderDetailByOptSql为新增显示字段供应商
 *   Jenny Li     2006-6-7   添加方法queryAddableSignedDetail，queryAddableSignedDetailCount，
 *                              getAddableSignedOrgDetailSql
 *   Jenny Li     2006-6-7   修改方法getAddableSignedOrgDetailSql增加查询字段
 *   Simonyi Peng 2006-10-23 修改方法getSignedProviderDetailSql，getSignedOrgDetailSql，增加查询字段gs_manufacture_id
 *   Simonyi Peng 2006-10-26 修改方法getSignedProviderDetailSql，getSignedOrgDetailSql，屏蔽查询条件里的签收时间判断
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room,
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun,
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import com.hitrust.gs.bean.GSOrderAnaDetailAndCategoryBean;
import com.hitrust.gs.bean.GSOrderAnaDetailBean;
import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSOrderDetailQueryBean;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.service.GSBaseBean;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSAddUnBalanceDetailQryResultVO;
import com.hitrust.gs.vo.GSBalancedDetailProvResultVO;
import com.hitrust.gs.vo.GSBalancedDetailQryResultVO;
import com.hitrust.gs.vo.GSDeliverOrderManufactureVO;
import com.hitrust.gs.vo.GSEmergencyOrderDetailVO;
import com.hitrust.gs.vo.GSOrderDetailModifyVO;
import com.hitrust.gs.vo.GSOrderMan4QueryVO;
import com.hitrust.gs.vo.GSOrderManufactureVO;
import com.hitrust.gs.vo.GSOrderManufactureVO_;
import com.hitrust.gs.vo.GSOrderQueryDetailExVO;
import com.hitrust.gs.vo.GSOrderStatusTraceDetailVO;
import com.hitrust.gs.vo.GSOrderSubmitDetailVO;
import com.hitrust.gs.vo.GSOrderSubmitForNonFlatVO;
import com.hitrust.gs.vo.GSOrderSubmitToApepQueryVO;
import com.hitrust.gs.vo.GSOrderVO;
import com.hitrust.gs.vo.GSUnBalanceDetailQryResultVO;
import com.hitrust.gs.vo.GSUnBalanceDetailQryVO;

/**
 * 
 */
public class GSOrderDetailDAO  extends GSBaseDAO
{
	/**
	 * 查询订单明细sql
	 * **/
	public static String getOrderAndDetailSql(){
		StringBuffer tSql =new StringBuffer("select det.*,");
		tSql.append(" ord.gs_authorize_date as gs_authorize_date_order,");
		tSql.append(" ord.gs_authorizer_id as gs_authorizer_id_order, ");
		tSql.append(" ord.gs_balance_mode as gs_balance_mode_order,");
		tSql.append(" ord.gs_deliver_goods_addr, ");
		tSql.append(" ord.gs_deliver_mode, ");
		tSql.append(" ord.gs_firstaudit_advices, ");
		tSql.append(" ord.gs_firstaudit_date, ");
		tSql.append(" ord.gs_firstauditor_id, ");
		tSql.append(" ord.gs_lastmodifer_id as gs_lastmodifer_id_order,");
		tSql.append(" ord.gs_lastmodify_contents as gs_lastmodify_contents_order, ");
		tSql.append(" ord.gs_lastmodify_date as gs_lastmodify_date_order,");
		tSql.append(" ord.gs_notes,");
		tSql.append(" ord.gs_order_category,");
		tSql.append(" ord.gs_order_contact_name, ");
		tSql.append(" ord.gs_order_contact_phone,");
		tSql.append(" ord.gs_order_create_date,");
		tSql.append(" ord.gs_order_status, ");
		tSql.append(" ord.gs_order_sum, ");
		tSql.append(" ord.gs_order_system_create_date, ");
		tSql.append(" ord.gs_order_tempid as gs_order_tempid_order,");
		tSql.append(" ord.gs_recorder_id,");
		tSql.append(" ord.gs_review_advices,");
		tSql.append(" ord.gs_review_date,");
		tSql.append(" ord.gs_reviewer_id,");
		tSql.append(" ord.gs_submit_date1, ");
		tSql.append(" ord.gs_submit_date2 as gs_submit_date2_order,");
		tSql.append(" ord.gs_submiter_id1, ");
		tSql.append(" ord.gs_submiter_id2 as gs_submiter_id2_order,");
		tSql.append(" ord.gs_workcorp_id,");
		tSql.append(" pro.adapt_machine_type, ");
		tSql.append(" pro.apep_code, ");
		tSql.append(" pro.appender_property,");
		tSql.append(" pro.area,");
		tSql.append(" pro.balance_customer_code, ");
		tSql.append(" pro.balance_mode, ");
		tSql.append(" pro.category_code,");
		tSql.append(" pro.concentricity_code, ");
		tSql.append(" pro.create_time as create_time_product,");
		tSql.append(" pro.create_user as create_user_product,");
		tSql.append(" pro.create_user_id as create_user_id_product,");
		tSql.append(" pro.drawing_piece_code, ");
		tSql.append(" pro.id as id_product,");
		tSql.append(" pro.is_buy, ");
		tSql.append(" pro.is_normal, ");
		tSql.append(" pro.is_tradeflat_product,");
		tSql.append(" pro.last_update_time as last_update_time_product,");
		tSql.append(" pro.last_update_user as last_update_user_product,");
		tSql.append(" pro.last_update_user_id as last_update_user_id_product,");
		tSql.append(" pro.manufaturer,");
		tSql.append(" pro.model,");
		tSql.append(" pro.name as name_product,");
		tSql.append(" pro.old_apep_code,");
		tSql.append(" pro.pic, ");
		tSql.append(" pro.product_brand,");
		tSql.append(" pro.product_unit, ");
		tSql.append(" pro.provider_code,");
		tSql.append(" pro.quality_assure_period, ");
		tSql.append(" pro.recent_adjusted_price, ");
		tSql.append(" pro.recent_adjustprice_date,");
		tSql.append(" pro.record_date,");
		tSql.append(" pro.recorder_id,");
		tSql.append(" pro.remark as remark_product, ");
		tSql.append(" pro.spec,");
		tSql.append(" pro.status as status_product, ");
		tSql.append(" pro.unit_price,");
		tSql.append(" pro.warehouse_code,");
		tSql.append(" pro.warehouse_name,pro.is_update,");
		tSql.append(" prv.*,");
		tSql.append(" war.address as address_warehouse,");
		tSql.append(" war.agent_flag,");
		tSql.append(" war.code as code_warehouse,");
		tSql.append(" war.contack_tel,");
		tSql.append(" war.contact_person,");
		tSql.append(" war.create_time as create_time_warehouse, ");
		tSql.append(" war.create_user as create_user_warehouse, ");
		tSql.append(" war.create_user_id as create_user_id_warehouse, ");
		tSql.append(" war.display_order,");
		tSql.append(" war.full_name as full_name_warehouse,");
		tSql.append(" war.id as id_warehouse, ");
		tSql.append(" war.is_show,");
		tSql.append(" war.last_update_time as last_update_time_warehouse,");
		tSql.append(" war.last_update_user as last_update_user_warehouse,");
		tSql.append(" war.last_update_user_id as last_update_user_id_warehouse,");
		tSql.append(" war.name as name_warehouse,");
		tSql.append(" war.remark, ");
		tSql.append(" war.status as status_warehouse");
		tSql.append(" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv");
		tSql.append(" where ");
		tSql.append(" ord.gs_order_tempid = det.gs_order_tempid ");
		tSql.append(" and det.gs_concentricity_id = pro.concentricity_code");
		tSql.append(" and det.gs_manufacture_id = pro.apep_code ");
		tSql.append(" and ord.gs_workcorp_id = war.code");
		tSql.append(" and pro.provider_code = prv.code ");;
		return tSql.toString();
	}

	/**
	 * 查询总金额SQL
	 * @author wp
	 * 2010-03-26
	 */
	public static String getOrderAndDetailAndCategorySqlTotalAmount() {
		StringBuffer tSql =new StringBuffer("select round(sum(det.gs_order_count * det.gs_goods_unitprice), 2)");

		tSql.append(" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv,T_PRODUCT_CATEGORY cat");
		tSql.append(" where ");
		tSql.append(" ord.gs_order_tempid = det.gs_order_tempid ");
		tSql.append(" and det.gs_concentricity_id = pro.concentricity_code");
		tSql.append(" and det.gs_manufacture_id = pro.apep_code ");
		tSql.append(" and ord.gs_workcorp_id = war.code");
		tSql.append(" and pro.provider_code = prv.code ");
		tSql.append(" and pro.CATEGORY_CODE = cat.code ");
		return tSql.toString();
	}


	/**
	 * 查询订单明细sql(包含产品分类)
	 * **/
	public static String getOrderAndDetailAndCategorySql(){
		StringBuffer tSql =new StringBuffer("select det.*,");
		tSql.append(" ord.gs_authorize_date as gs_authorize_date_order,");
		tSql.append(" ord.gs_authorizer_id as gs_authorizer_id_order, ");
		tSql.append(" ord.gs_balance_mode as gs_balance_mode_order,");
		tSql.append(" ord.gs_deliver_goods_addr, ");
		tSql.append(" ord.gs_deliver_mode, ");
		tSql.append(" ord.gs_firstaudit_advices, ");
		tSql.append(" ord.gs_firstaudit_date, ");
		tSql.append(" ord.gs_firstauditor_id, ");
		tSql.append(" ord.gs_lastmodifer_id as gs_lastmodifer_id_order,");
		tSql.append(" ord.gs_lastmodify_contents as gs_lastmodify_contents_order, ");
		tSql.append(" ord.gs_lastmodify_date as gs_lastmodify_date_order,");
		tSql.append(" ord.gs_notes,");
		tSql.append(" ord.gs_order_category,");
		tSql.append(" ord.gs_order_contact_name, ");
		tSql.append(" ord.gs_order_contact_phone,");
		tSql.append(" ord.gs_order_create_date,");
		tSql.append(" ord.gs_order_status, ");
		tSql.append(" ord.gs_order_sum, ");
		tSql.append(" ord.gs_order_system_create_date, ");
		tSql.append(" ord.gs_order_tempid as gs_order_tempid_order,");
		tSql.append(" ord.gs_recorder_id,");
		tSql.append(" ord.gs_review_advices,");
		tSql.append(" ord.gs_review_date,");
		tSql.append(" ord.gs_reviewer_id,");
		tSql.append(" ord.gs_submit_date1, ");
		tSql.append(" ord.gs_submit_date2 as gs_submit_date2_order,");
		tSql.append(" ord.gs_submiter_id1, ");
		tSql.append(" ord.gs_submiter_id2 as gs_submiter_id2_order,");
		tSql.append(" ord.gs_workcorp_id,");
		tSql.append(" pro.adapt_machine_type, ");
		tSql.append(" pro.apep_code, ");
		tSql.append(" pro.appender_property,");
		tSql.append(" pro.area,");
		tSql.append(" pro.balance_customer_code, ");
		tSql.append(" pro.balance_mode, ");
		tSql.append(" pro.category_code,");
		tSql.append(" pro.concentricity_code, ");
		tSql.append(" pro.create_time as create_time_product,");
		tSql.append(" pro.create_user as create_user_product,");
		tSql.append(" pro.create_user_id as create_user_id_product,");
		tSql.append(" pro.drawing_piece_code, ");
		tSql.append(" pro.id as id_product,");
		tSql.append(" pro.is_buy, ");
		tSql.append(" pro.is_normal, ");
		tSql.append(" pro.is_tradeflat_product,");
		tSql.append(" pro.last_update_time as last_update_time_product,");
		tSql.append(" pro.last_update_user as last_update_user_product,");
		tSql.append(" pro.last_update_user_id as last_update_user_id_product,");
		tSql.append(" pro.manufaturer,");
		tSql.append(" pro.model,");
		tSql.append(" pro.name as name_product,");
		tSql.append(" pro.old_apep_code,");
		tSql.append(" pro.pic, ");
		tSql.append(" pro.product_brand,");
		tSql.append(" pro.product_unit, ");
		tSql.append(" pro.provider_code,");
		tSql.append(" pro.quality_assure_period, ");
		tSql.append(" pro.recent_adjusted_price, ");
		tSql.append(" pro.recent_adjustprice_date,");
		tSql.append(" pro.record_date,");
		tSql.append(" pro.recorder_id,");
		tSql.append(" pro.remark as remark_product, ");
		tSql.append(" pro.spec,");
		tSql.append(" pro.status as status_product, ");
		tSql.append(" pro.unit_price,");
		tSql.append(" pro.warehouse_code,");
		tSql.append(" pro.warehouse_name,pro.is_update,");
		tSql.append(" prv.*,");
		tSql.append(" war.address as address_warehouse,");
		tSql.append(" war.agent_flag,");
		tSql.append(" war.code as code_warehouse,");
		tSql.append(" war.contack_tel,");
		tSql.append(" war.contact_person,");
		tSql.append(" war.create_time as create_time_warehouse, ");
		tSql.append(" war.create_user as create_user_warehouse, ");
		tSql.append(" war.create_user_id as create_user_id_warehouse, ");
		tSql.append(" war.display_order,");
		tSql.append(" war.full_name as full_name_warehouse,");
		tSql.append(" war.id as id_warehouse, ");
		tSql.append(" war.is_show,");
		tSql.append(" war.last_update_time as last_update_time_warehouse,");
		tSql.append(" war.last_update_user as last_update_user_warehouse,");
		tSql.append(" war.last_update_user_id as last_update_user_id_warehouse,");
		tSql.append(" war.name as name_warehouse,");
		tSql.append(" war.remark, ");
		tSql.append(" war.status as status_warehouse,");
		tSql.append(" cat.CODE as code_category,");
		tSql.append(" cat.NAME as name_category,");
		tSql.append(" cat.UPPER_CATEGORY,");
		tSql.append(" cat.CATEGORY_LEVEL,");
		tSql.append(" cat.CATEGORY_ID1,");
		tSql.append(" cat.CATEGORY_ID2");
		tSql.append(" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv,T_PRODUCT_CATEGORY cat");
		tSql.append(" where ");
		tSql.append(" ord.gs_order_tempid = det.gs_order_tempid ");
		tSql.append(" and det.gs_concentricity_id = pro.concentricity_code");
		tSql.append(" and det.gs_manufacture_id = pro.apep_code ");
		tSql.append(" and ord.gs_workcorp_id = war.code");
		tSql.append(" and pro.provider_code = prv.code ");
		tSql.append(" and pro.CATEGORY_CODE = cat.code ");
		return tSql.toString();
	}
	
	
	/**
	 * 查询订单明细sql(包含产品分类)
	 * **/
	public static String getOrderAndDetailAndCategorySqlNew(){
		StringBuffer tSql =new StringBuffer("select distinct ord.gs_order_tempid as gs_order_tempid_order,sum(det.gs_order_count) gs_order_count ,sum(det.gs_signin_count) gs_signin_count ");
		tSql.append(" ,count(det.gs_order_detail_id) gs_order_detail_id ,war.full_name as full_name_warehouse,ord.gs_deliver_goods_addr,ord.gs_order_contact_name,ord.gs_order_contact_phone,ord.gs_order_create_date  ");
		tSql.append(" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv,T_PRODUCT_CATEGORY cat");
		tSql.append(" where ");
		tSql.append(" ord.gs_order_tempid = det.gs_order_tempid ");
		tSql.append(" and det.gs_concentricity_id = pro.concentricity_code");
		tSql.append(" and det.gs_manufacture_id = pro.apep_code ");
		tSql.append(" and ord.gs_workcorp_id = war.code");
		tSql.append(" and pro.provider_code = prv.code ");
		tSql.append(" and pro.CATEGORY_CODE = cat.code ");
		return tSql.toString();
	}


	/***
	 *根据订单明细编号查询订单详细信息
	 * **/
	public GSOrderAnaDetailAndCategoryBean getOrderDetailByDetailId(String detailId) throws GSException{
		StringBuffer tSql=new StringBuffer(getOrderAndDetailAndCategorySql());
		tSql.append(" and  det.gs_order_detail_id=?");
		Object[] tObj={detailId};
		GSOrderAnaDetailAndCategoryBean tmp=null;
		ArrayList orderDetailList=new ArrayList();
		try {
			orderDetailList = this.executeQuery(new GSOrderAnaDetailAndCategoryBean(), tSql.toString(), tObj);
		} catch (Exception e) {
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		if (orderDetailList.size()==1) {
			tmp=(GSOrderAnaDetailAndCategoryBean) orderDetailList.get(0);
		}
		return tmp;
	}
	/***
	 *根据送货单号查询所有订单明细
	 * **/
	public ArrayList getOrderDetailByGoodId(String goodsId) throws GSException{
		StringBuffer tSql=new StringBuffer(getOrderAndDetailAndCategorySql());
		tSql.append(" and  det.GS_DELIVER_GOODS_ID = '"+goodsId+"' and det.GS_ORDER_DETAIL_STATUS in ('10')");
		ArrayList orderDetailList=new ArrayList();
		Object[] tObj={};
		try {
			orderDetailList = this.executeQuery(new GSOrderAnaDetailAndCategoryBean(), tSql.toString(), tObj);
		} catch (Exception e) {
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return orderDetailList;
	}
	/**
	 * 根据订单编号查询订单所订的全部产品信息
	 * @param aOrderId
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetail(String aOrderId) throws GSException
	{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select b.GS_MANUFACTURE_ID as P1,b.GS_MANUFACTURE_NAME as P2,");
		tSql.append("b.GS_MANUFACTURE_UNITPRICE as P3,a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("c.GS_ORG_NAME as P7,a.GS_DELIVER_GOODS_ADDR as P8,a.GS_ORDER_CONTACT_NAME as P9,a.GS_ORDER_CONTACT_PHONE as P10,");
		tSql.append("a.GS_DELIVER_MODE as P11,a.GS_BALANCE_MODE as P12,d.GS_PROVIDER_NAME as P13, a.GS_ORDER_TEMPID as P14,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P15,a.GS_ORDER_DETAIL_NOTE as P16,a.GS_ORDER_DETAIL_STATUS as P17,b.GS_IS_TRADEFLAT_MANUFACTURE as P18,b.GS_QUANT_UNIT as P19");
		tSql.append(",a.GS_CONCENTRICITY_ID as P20,b.GS_QUANT_UNIT as P21 ");
		tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID ");
		tSql.append("and a.GS_MANUFACTURE_ID is NOT NULL and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID ");
		tSql.append("and a.GS_ORDER_DEPT_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID ");
		tSql.append("union ");
		tSql.append("select '' as P1,'' as P2,");
		tSql.append("0 as P3,a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("c.GS_ORG_NAME as P7,a.GS_DELIVER_GOODS_ADDR as P8,a.GS_ORDER_CONTACT_NAME as P9,a.GS_ORDER_CONTACT_PHONE as P10,");
		tSql.append("a.GS_DELIVER_MODE as P11,a.GS_BALANCE_MODE as P12,d.GS_PROVIDER_NAME as P13, a.GS_ORDER_TEMPID as P14,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P15,a.GS_ORDER_DETAIL_NOTE as P16,a.GS_ORDER_DETAIL_STATUS as P17,'' as P18,'' as P19");
		tSql.append(",a.GS_CONCENTRICITY_ID as P20,b.GS_QUANT_UNIT as P21 ");
		tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID ");
		tSql.append("and a.GS_MANUFACTURE_ID is NULL ");
		tSql.append("and a.GS_ORDER_DEPT_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID ");

		Object[] tObj = {aOrderId,aOrderId};
		try{
			tList = executeQuery(new GSOrderMan4QueryVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 运营公司级根据订单编号查询待提交订单
	 * @param aOrderId              订单编号
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderSubmitDetail(String aOrderId) throws GSException{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select distinct a.GS_CONCENTRICITY_ID as P1,b.NAME as P2,");
		tSql.append("a.GS_ORDER_COUNT as P3,a.GS_DELIVER_GOODS_DATE as P4,a.GS_DELIVER_GOODS_TIME as P5,");
		tSql.append("b.SPEC as P6,b.MODEL as P7,b.PRODUCT_BRAND as P8,");
		tSql.append("b.PRODUCT_UNIT as P9, a.GS_ORDER_TEMPID as P10,a.GS_ORDER_DETAIL_ID as P11,a.GS_GOODS_UNITPRICE as P12,b.QUALITY_ASSURE_PERIOD as P13 ");
		tSql.append("from GS_ORDER_DETAIL a,t_product b,t_provider c ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_CONCENTRICITY_ID=b.CONCENTRICITY_CODE ");
		tSql.append("and c.code=a.GS_PROVIDER_ID ");
		tSql.append("and (a.gs_manufacture_id is null or (a.gs_manufacture_id is not null and a.gs_manufacture_id=b.APEP_CODE))");

		Object[] tObj = {aOrderId};
		GSLogWriter.debug("sql=" + tSql.toString());
		try{
			tList = executeQuery(new GSOrderSubmitDetailVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	
	//增加图件号的查询
	public ArrayList queryOrderSubmitDetailAddDrawing(String aOrderId) throws GSException{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select distinct a.GS_CONCENTRICITY_ID as P1,b.NAME as P2,");
		tSql.append("a.GS_ORDER_COUNT as P3,a.GS_DELIVER_GOODS_DATE as P4,a.GS_DELIVER_GOODS_TIME as P5,");
		tSql.append("b.SPEC as P6,b.MODEL as P7,b.PRODUCT_BRAND as P8,");
		tSql.append("b.PRODUCT_UNIT as P9, a.GS_ORDER_TEMPID as P10,a.GS_ORDER_DETAIL_ID as P11,a.GS_GOODS_UNITPRICE as P12,b.QUALITY_ASSURE_PERIOD as P13," +
				"b.DRAWING_PIECE_CODE as P14 ");
		tSql.append("from GS_ORDER_DETAIL a,t_product b,t_provider c ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_CONCENTRICITY_ID=b.CONCENTRICITY_CODE ");
		tSql.append("and c.code=a.GS_PROVIDER_ID ");
		tSql.append("and (a.gs_manufacture_id is null or (a.gs_manufacture_id is not null and a.gs_manufacture_id=b.APEP_CODE))");

		Object[] tObj = {aOrderId};
		GSLogWriter.debug("sql=" + tSql.toString());
		try{
			tList = executeQuery(new GSOrderSubmitDetailVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 运营公司级查询订单信息
	 * @param aOrderId      订单编号
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderQueryDetail(String aOrderId) throws GSException{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.NAME as P3,");
		tSql.append("b.SPEC as P4,b.model as P5,b.PRODUCT_BRAND as P6,a.GS_ORDER_COUNT as P7,");
		tSql.append("a.GS_ORDER_DETAIL_STATUS as P8,b.PRODUCT_UNIT as P9,a.GS_GOODS_UNITPRICE as P10,a.GS_DELIVER_GOODS_DATE as P11,");
		tSql.append("a.GS_DELIVER_GOODS_TIME as P12,a.GS_AUTHORIZE_ADVICES as P13,b.QUALITY_ASSURE_PERIOD as P14,");
		tSql.append("a.GS_AUTHORIZER_ID as P15,a.GS_AUTHORIZE_DATE as P16,a.GS_CANCEL_DATE as P17,a.GS_CANCEL_CAUSE as P18,a.GS_CANCEL_PERSON as P19,");
		tSql.append("a.GS_REJECT_CAUSE as P20,a.GS_REJECT_DATE as P21,a.GS_REJECT_TIME as P22,a.GS_DELIVER_GOODS_ID as P23,");
		tSql.append("a.GS_DELIVER_GOODS_CONFIRM_DATE as P24,a.GS_DELIVER_GOODS_CONFIRM_TIME as P25,a.GS_DELIVERYMAN as P26,");
		tSql.append("a.GS_DELIVER_GOODS_PHONE as P27,a.GS_DELIVER_GOODS_COUNTS as P28,a.GS_SIGNIN_DATE as P29,");
		tSql.append("a.GS_SIGNIN_PERSON as P30,a.GS_SIGNIN_COUNT as P31, b.PROVIDER_CODE as P32, e.name as P33 ");
		tSql.append("from GS_ORDER_DETAIL a,t_product b,T_WAREHOUSE c,GS_ORDER d,T_PROVIDER e ");
		tSql.append("where d.GS_ORDER_TEMPID=? and a.GS_ORDER_TEMPID=d.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID=b.CONCENTRICITY_CODE ");
		tSql.append("and ((a.GS_MANUFACTURE_ID is NOT NULL and a.GS_MANUFACTURE_ID= b.APEP_CODE and b.PROVIDER_CODE = e.code)");
		tSql.append(" or a.GS_MANUFACTURE_ID IS NULL) ");
		tSql.append("and d.GS_WORKCORP_ID=c.CODE ");
		tSql.append("order by a.GS_LASTMODIFY_DATE desc");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSOrderQueryDetailExVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	public ArrayList queryOrderStatusTraceDetail(String aOrderId) throws GSException{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_MANUFACTURE_SPEC as P4,b.GS_MANUFACTURE_TYPE as P5,b.GS_MANUFACTURE_BRAND as P6,a.GS_ORDER_COUNT as P7,");
		tSql.append("a.GS_ORDER_DETAIL_STATUS as P8,b.GS_QUANT_UNIT as P9,a.GS_GOODS_UNITPRICE as P10,");
		tSql.append("a.GS_DELIVER_GOODS_DATE as P11,a.GS_DELIVER_GOODS_TIME as P12,b.GS_QUALITY_ASSURE_PERIOD as P13 ");
		tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_ORDER d ");
		tSql.append("where d.GS_ORDER_TEMPID=? and a.GS_ORDER_TEMPID=d.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID ");
		tSql.append("and ((a.GS_MANUFACTURE_ID is NOT NULL and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID)");
		tSql.append(" or a.GS_MANUFACTURE_ID IS NULL) ");
		tSql.append("and d.GS_WORKCORP_ID=c.GS_ORG_ID ");
		tSql.append("order by a.GS_LASTMODIFY_DATE desc");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSOrderStatusTraceDetailVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询订单详细信息，FOR订单录入的结果页面显示
	 * @param aOrderId
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetail_(String aOrderId) throws GSException {
		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select b.APEP_CODE as P1,b.NAME as P2,a.GS_CONCENTRICITY_ID as P3,");
		tSql.append("a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("b.SPEC as P7,b.MODEL as P8,b.PRODUCT_BRAND as P9,");
		tSql.append("b.PRODUCT_UNIT as P10,a.GS_GOODS_UNITPRICE as P11,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P13,a.GS_ORDER_TEMPID as P14, ");
		tSql.append("a.GS_REJECT_CAUSE as P15,a.GS_AUTHORIZE_ADVICES as P16,a.GS_GOODS_UNITPRICE as P17,b.QUALITY_ASSURE_PERIOD as P18,");
		tSql.append("c.CODE as P19,c.NAME as P20, ");
		tSql.append("b.IS_TRADEFLAT_PRODUCT as P21,c.IS_TRADEFLAT_PROVIDER as P22,a.gs_order_detail_status as P23,a.gs_balance_category_no as P24,a.gs_balance_mode as P25 ");
		tSql.append("from GS_ORDER_DETAIL a,t_product b,t_provider c ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_MANUFACTURE_ID= b.APEP_CODE and a.gs_provider_id = c.code ");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSOrderManufactureVO_(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;

	}

	/**
	 * 查询订单详细信息，FOR订单录入的结果页面显示
	 * @param aOrderId
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetailWithStausReconfirm(String aOrderId) throws GSException {
		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select b.apep_code as P1,b.NAME as P2,a.GS_CONCENTRICITY_ID as P3,");
		tSql.append("a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("b.SPEC as P7,b.MODEL as P8,b.PRODUCT_BRAND as P9,");
		tSql.append("b.PRODUCT_UNIT as P10,a.GS_GOODS_UNITPRICE as P11,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P13,a.GS_ORDER_TEMPID as P14, ");
		tSql.append("a.GS_REJECT_CAUSE as P15,a.GS_AUTHORIZE_ADVICES as P16,a.GS_GOODS_UNITPRICE as P17,b.QUALITY_ASSURE_PERIOD as P18,");
		tSql.append("c.CODE as P19,c.name as P20, ");
		tSql.append("b.IS_TRADEFLAT_PRODUCT as P21,c.IS_TRADEFLAT_PROVIDER as P22,a.gs_order_detail_status as P23,a.gs_balance_category_no as P24,a.gs_balance_mode as P25 ");
		tSql.append("from GS_ORDER_DETAIL a,t_product b,t_PROVIDER c ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_MANUFACTURE_ID= b.apep_code and a.gs_provider_id = c.code  and a.GS_ORDER_DETAIL_STATUS='3'");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSOrderManufactureVO_(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;

	}

	/**
	 * 查询订单详细信息，FOR送货单录入的结果页面显示
	 * @param aOrderId
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryDeliverOrderDetail(String aOrderId) throws GSException {
		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select b.GS_MANUFACTURE_ID as P1,b.GS_MANUFACTURE_NAME as P2,");
		tSql.append("a.GS_CONCENTRICITY_ID as P3,a.GS_ORDER_COUNT as P4,b.gs_manufacturer_name as P5,");
		tSql.append("b.GS_MANUFACTURE_SPEC as P6,b.GS_MANUFACTURE_TYPE as P7,b.GS_MANUFACTURE_BRAND as P8,");
		tSql.append("b.GS_QUANT_UNIT as P9,a.GS_GOODS_UNITPRICE as P10,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P11,a.GS_ORDER_TEMPID as P12, ");
		tSql.append("a.GS_DELIVER_GOODS_ID as P13,c.gs_provider_id as P14,");
		tSql.append("c.gs_provider_shortname as P15,a.gs_order_detail_status as P16,  ");
		tSql.append("a.gs_signin_date as P17,a.gs_signin_person as P18  ");
		tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_PROVIDER c ");
		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID and a.gs_provider_id = c.gs_provider_id ");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSDeliverOrderManufactureVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;

	}
	/**
	 * 查询所有已核准的订单明细
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryAllAuthoriseOrders(GSOrderSubmitToApepQueryVO aVO,int pageNo,int pageSize) throws GSException{
		ArrayList tList = new ArrayList();
		StringBuffer tSql = new StringBuffer();
		tSql.append(getSql(aVO));
		tSql.append(" order by a.GS_LASTMODIFY_DATE desc");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tList = executeQuery(new GSOrderSubmitToApepQueryVO(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	private String getSql(GSOrderSubmitToApepQueryVO aVO)throws GSException{
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.name as P3,");
		tSql.append("b.IS_TRADEFLAT_PRODUCT as P4,b.DRAWING_PIECE_CODE as DRAWING_PIECE_CODE,b.SPEC as P5,b.MODEL as P6,b.PRODUCT_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.PRODUCT_UNIT as P9,d.name as P10,c.name as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,a.GS_DELIVER_GOODS_DATE as P13,a.GS_DELIVER_GOODS_TIME as P14,a.GS_ORDER_TEMPID as P15,");
		tSql.append("d.code as P16,d.IS_TRADEFLAT_PROVIDER as P17,a.GS_LASTMODIFY_DATE,a.gs_balance_mode as P18,b.is_normal as P19 ");
		tSql.append(" from GS_ORDER_DETAIL a,t_product b,t_warehouse c,t_provider d,GS_ORDER e, ");
		tSql.append(" T_PRODUCT_CATEGORY g ");
		tSql.append(" where e.GS_ORDER_TEMPID = a.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID= b.CONCENTRICITY_CODE");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.APEP_CODE");
		tSql.append(" and e.GS_WORKCORP_ID=c.code and d.code=a.GS_PROVIDER_ID");
		tSql.append(" and a.GS_ORDER_DETAIL_STATUS='7' ");//and d.IS_TRADEFLAT_PROVIDER ='0'
		//tSql.append(" and (b.GS_IS_TRADEFLAT_MANUFACTURE='0' or b.GS_IS_TRADEFLAT_MANUFACTURE='1')"); //2006-3-29 添加限制产品为网上产品
		//添加限制不显示明确提交失败的订单
		tSql.append(" and a.GS_ORDERRETURN_SIGN in ('"+GSBaseConstants.APEP_RETURN_SIGN_SUCCESS+"','-1') ");

		if(aVO.orderCreateDateStr != null  && aVO.orderCreateDateStr.trim().length()!= 0) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		}
		if(aVO.orderCreateDateEnd != null  && aVO.orderCreateDateEnd.trim().length()!= 0) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		}
		tSql.append(" and b.CATEGORY_CODE = g.code");

		if(aVO.orderDetailId != null && aVO.orderDetailId.trim().length() != 0){
			tSql.append(" and a.GS_ORDER_DETAIL_ID ='"+ aVO.orderDetailId + "'");
		}
		if(aVO.providerName != null && aVO.providerName.trim().length() != 0){
			tSql.append(" and (d.full_name ='"+ aVO.providerName + "'");
			tSql.append(" or d.name='" + aVO.providerName + "')");
		}

		if (aVO.orderDeptId != null) {
			tSql.append(" and e.GS_WORKCORP_ID like '" + aVO.orderDeptId + "%'");
		}
		if(aVO.concentricityId != null && aVO.concentricityId.trim().length() != 0){
			tSql.append(" and a.GS_CONCENTRICITY_ID like '%" + aVO.concentricityId + "%'");
		}
		if(aVO.manufInfo != null && aVO.manufInfo.trim().length() != 0){
			tSql.append(" and (b.NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.MODEL like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.UNIT_PRICE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.PRODUCT_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.MANUFATURER like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manuftype1 != null){
			if(aVO.manuftype1.equals("0")){
				tSql.append(" and g.CODE like '%'");
			}else if(aVO.manuftype2.equals("0")){
				tSql.append(" and (g.CATEGORY_ID1 ='" + aVO.manuftype1 + "'");
				tSql.append(" or g.CODE='" + aVO.manuftype1 + "')");
			}else if(aVO.manuftype3.equals("0")){
				tSql.append(" and (g.CATEGORY_ID2 ='" + aVO.manuftype2 + "'");
				tSql.append(" or g.CODE='" + aVO.manuftype2 + "')");
			}else{
				tSql.append(" and g.CODE ='" + aVO.manuftype3 + "'");
			}
		}
		//图件号
		if(aVO.drawingpiececode != null && !aVO.drawingpiececode.equals("")){
			tSql.append(" and b.DRAWING_PIECE_CODE like '%" + aVO.drawingpiececode.trim() + "%'");
		}
		return tSql.toString();
	}
	public int queryAllAuthoriseOrdersCount(GSOrderSubmitToApepQueryVO aVO) throws GSException{

		Object[] tObj = {};
		int size = 0;
		try{
			StringBuffer tSql = new StringBuffer("select count(*) from (");
			tSql.append(getSql(aVO));
			tSql.append(")");
			size = this.queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			e.printStackTrace();
		}
		return size;
	}
	/**
	 * 根据订单明细编码查询订单明细
	 * @param aOrderDetailId
	 * @return
	 * @throws GSException
	 */
	public GSOrderDetailBean queryOrderDetailByDetailId(String aOrderDetailId) throws GSException{
		String tSql = "select * from GS_ORDER_DETAIL where GS_ORDER_DETAIL_ID=?";
		Object[] tObj = {aOrderDetailId};
		GSOrderDetailBean tOrderDetailBean = new GSOrderDetailBean();
		try{
			ArrayList tList = this.executeQuery(new GSOrderDetailBean(),tSql,tObj);
			if(tList.size() > 0){
				tOrderDetailBean = (GSOrderDetailBean)tList.get(0);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tOrderDetailBean;
	}

	/**
	 * 根据订单明细编码数组查询一组订单明细信息
	 */
	public ArrayList queryOrderDetailByDetailIds(String[] aOrderDetailIds) throws GSException {
		if(aOrderDetailIds == null || aOrderDetailIds.length == 0) {
			return null;
		}

		String tSql = "select * from GS_ORDER_DETAIL where GS_ORDER_DETAIL_ID in ";

		StringBuffer tStrBuffer = new StringBuffer("(");
		for(int i=0; i<aOrderDetailIds.length; i++) {
			if(i != 0) {
				tStrBuffer.append(",");
			}
			tStrBuffer.append("'").append(aOrderDetailIds[i]).append("'");
			if(i == aOrderDetailIds.length - 1) {
				tStrBuffer.append(")");
			}
		}
		tSql += tStrBuffer.toString();

		Object[] tObj = {};
		try {
			ArrayList tList = this.executeQuery(new GSOrderDetailBean(),tSql,tObj);
			return tList;
		} catch (Exception e) {
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}


	}

	/**
	 * 根据订单明细编码查询订单明细信息
	 * @param aConn                 DB连接
	 * @param aOrderDetailId        订单明细编码
	 * @return
	 * @throws GSException
	 */
	public GSOrderDetailBean queryOrderDetailByDetailId(Connection aConn,String aOrderDetailId) throws GSException{
		String tSql = "select * from GS_ORDER_DETAIL where GS_ORDER_DETAIL_ID=?";
		Object[] tObj = {aOrderDetailId};
		GSOrderDetailBean tOrderDetailBean = null;
		try{
			ArrayList tList = this.executeQuery(aConn,new GSOrderDetailBean(),tSql,tObj);
			if(tList.size() > 0){
				tOrderDetailBean = (GSOrderDetailBean)tList.get(0);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tOrderDetailBean;
	}

	/**
	 * 根据订单明细编码查询订单状态为核准的
	 * 订单明细及订单包含的产品信息
	 * @param aConn                         DB连接
	 * @param aOrderDetailId                订单明细编码
	 * @return
	 * @throws GSException
	 */
	public GSOrderManufactureVO queryAuthoriseOrderDetailByDetailId(Connection aConn,String aOrderDetailId) throws GSException{
		StringBuffer tSql = new StringBuffer("select b.GS_MANUFACTURE_ID as P1,b.GS_MANUFACTURE_NAME as P2,");
		tSql.append("b.GS_MANUFACTURE_UNITPRICE as P3,a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("c.GS_ORG_NAME as P7,e.GS_DELIVER_GOODS_ADDR as P8,e.GS_ORDER_CONTACT_NAME as P9,e.GS_ORDER_CONTACT_PHONE as P10,");
		tSql.append("e.GS_DELIVER_MODE as P11,e.GS_BALANCE_MODE as P12,d.GS_PROVIDER_NAME as P13, a.GS_ORDER_TEMPID as P14,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P15,a.GS_ORDER_DETAIL_NOTE as P16,a.GS_ORDER_DETAIL_STATUS as P17,b.GS_IS_TRADEFLAT_MANUFACTURE as P18");
		tSql.append(",b.GS_QUANT_UNIT as P19,a.GS_CONCENTRICITY_ID as P20");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e ");
		tSql.append(" where e.GS_ORDER_TEMPID = a.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID");
		tSql.append(" and a.GS_ORDER_DETAIL_STATUS='9' and a.GS_ORDER_DETAIL_ID=? ");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {aOrderDetailId};
		GSOrderManufactureVO tOrderManufVO= null;
		try{
			ArrayList tList = this.executeQuery(aConn, new GSOrderManufactureVO(),tSql.toString(),tObj);
			if(tList.size() > 0){
				tOrderManufVO = (GSOrderManufactureVO)tList.get(0);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tOrderManufVO;
	}
	public GSOrderManufactureVO queryOrderDetailById(Connection aConn,String aOrderDetailId) throws GSException{
		StringBuffer tSql = new StringBuffer("select b.APEP_CODE as P1,b.NAME as P2,");
		tSql.append("b.UNIT_PRICE as P3,a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
		tSql.append("c.name as P7,e.GS_DELIVER_GOODS_ADDR as P8,e.GS_ORDER_CONTACT_NAME as P9,e.GS_ORDER_CONTACT_PHONE as P10,");
		tSql.append("e.GS_DELIVER_MODE as P11,e.GS_BALANCE_MODE as P12,d.full_name as P13, a.GS_ORDER_TEMPID as P14,");
		tSql.append("a.GS_ORDER_DETAIL_ID as P15,e.GS_NOTES as P16,a.GS_ORDER_DETAIL_STATUS as P17,b.IS_TRADEFLAT_PRODUCT as P18");
		tSql.append(",b.PRODUCT_UNIT as P19,a.GS_CONCENTRICITY_ID as P20");
		tSql.append(" from GS_ORDER_DETAIL a,t_product b,t_warehouse c,t_provider d,GS_ORDER e ");
		tSql.append(" where e.GS_ORDER_TEMPID = a.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID=b.CONCENTRICITY_CODE");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.APEP_CODE");
		tSql.append(" and e.GS_WORKCORP_ID=c.code and d.code=a.GS_PROVIDER_ID");
		tSql.append(" and a.GS_ORDER_DETAIL_ID=? ");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {aOrderDetailId};
		GSOrderManufactureVO tOrderManufVO= null;
		try{
			ArrayList tList = this.executeQuery(aConn, new GSOrderManufactureVO(),tSql.toString(),tObj);
			if(tList.size() > 0){
				tOrderManufVO = (GSOrderManufactureVO)tList.get(0);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tOrderManufVO;
	}
	/**
	 * 修改订单明细状态
	 * @param aOrderDetailId        订单明细编码
	 * @param aStatus               状态
	 * @param aOperId               操作员编码
	 * @param aConn                 DB连接
	 * @return
	 * @throws GSException
	 */
	public boolean updateOrderDetailStatus(GSOrderDetailBean aOrderDetailBean,Connection aConn,String aOldStatus) throws GSException{
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_ORDER_DETAIL_STATUS='" + aOrderDetailBean.getGs_order_detail_status() + "'");
		if(aOrderDetailBean.getGs_lastmodifer_id() != null){
			tSql.append(",GS_LASTMODIFER_ID='" + aOrderDetailBean.getGs_lastmodifer_id() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_date() != null){
			tSql.append(",GS_LASTMODIFY_DATE='" + aOrderDetailBean.getGs_lastmodify_date() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_contents() != null){
			tSql.append(",GS_LASTMODIFY_CONTENTS='" + aOrderDetailBean.getGs_lastmodify_contents() + "'");
		}

		if(aOrderDetailBean.getGs_deliver_goods_id() != null){
			tSql.append(",GS_DELIVER_GOODS_ID='" + aOrderDetailBean.getGs_deliver_goods_id() + "'");
		}
		if(aOrderDetailBean.getGs_deliveryman() != null){
			tSql.append(",GS_DELIVERYMAN='" + aOrderDetailBean.getGs_deliveryman() + "'");
		}
		if(aOrderDetailBean.getGs_deliver_goods_phone() != null){
			tSql.append(",GS_DELIVER_GOODS_PHONE='" + aOrderDetailBean.getGs_deliver_goods_phone() + "'");
		}
		if(aOrderDetailBean.getGs_deliver_goods_counts() != 0){
			tSql.append(",GS_DELIVER_GOODS_COUNTS=" + aOrderDetailBean.getGs_deliver_goods_counts());
		}
		if(aOrderDetailBean.getGs_deliver_goods_confirm_date() != null){
			tSql.append(",GS_DELIVER_GOODS_CONFIRM_DATE='" + aOrderDetailBean.getGs_deliver_goods_confirm_date() + "'");
		}
		if(aOrderDetailBean.getGs_deliver_goods_confirm_time() != null){
			tSql.append(",GS_DELIVER_GOODS_CONFIRM_TIME='" + aOrderDetailBean.getGs_deliver_goods_confirm_time() + "'");
		}
		if(aOrderDetailBean.getGs_deliver_goods_explain() != null){
			tSql.append(",GS_DELIVER_GOODS_EXPLAIN='" + aOrderDetailBean.getGs_deliver_goods_explain() + "'");
		}

		if(aOrderDetailBean.getGs_reject_cause() != null){
			tSql.append(",GS_REJECT_CAUSE='" + aOrderDetailBean.getGs_reject_cause() + "'");
		}
		if(aOrderDetailBean.getGs_reject_date() != null){
			tSql.append(",GS_REJECT_DATE='" + aOrderDetailBean.getGs_reject_date() + "'");
		}
		if(aOrderDetailBean.getGs_reject_date() != null){
			tSql.append(",GS_REJECT_TIME='" + aOrderDetailBean.getGs_reject_time() + "'");
		}

		if(aOrderDetailBean.getGs_signin_count() != 0){
			tSql.append(",GS_SIGNIN_COUNT=" + aOrderDetailBean.getGs_signin_count());
		}
		if(aOrderDetailBean.getGs_signin_date() != null){
			tSql.append(",GS_SIGNIN_DATE='" + aOrderDetailBean.getGs_signin_date()+"'");
		}
		if(aOrderDetailBean.getGs_signin_time() != null){
			tSql.append(",GS_SIGNIN_TIME='" + aOrderDetailBean.getGs_signin_time() + "'");
		}
		if(aOrderDetailBean.getGs_signin_person() != null){
			tSql.append(",GS_SIGNIN_PERSON='" + aOrderDetailBean.getGs_signin_person() +"'");
		}
		if(aOrderDetailBean.getGs_signin_explain() != null){
			tSql.append(",GS_SIGNIN_EXPLAIN='" + aOrderDetailBean.getGs_signin_explain() + "'");
		}
		if(aOrderDetailBean.getGs_goods_unitprice() != 0){
			tSql.append(",GS_GOODS_UNITPRICE=" + aOrderDetailBean.getGs_goods_unitprice());
		}
		if(aOrderDetailBean.getGs_submiter_id2() != null){
			tSql.append(",GS_SUBMITER_ID2='" + aOrderDetailBean.getGs_submiter_id2() +"'");
		}
		if(aOrderDetailBean.getGs_submit_date2() != null){
			tSql.append(",GS_SUBMIT_DATE2='" + aOrderDetailBean.getGs_submit_date2() + "'");
		}

		if(aOrderDetailBean.getGs_manufacture_id() != null){
			tSql.append(",GS_MANUFACTURE_ID='" + aOrderDetailBean.getGs_manufacture_id() +"'");
		}
		if(aOrderDetailBean.getGs_order_count() != 0){
			tSql.append(",GS_ORDER_COUNT=" + aOrderDetailBean.getGs_order_count());
		}
		//add 2006-4-24 for balance
		if(aOrderDetailBean.getGs_is_balanced() != null){
			tSql.append(",GS_IS_BALANCEED='" + aOrderDetailBean.getGs_is_balanced() + "'");
		}
		//add 2006-11-18 for balance
		if(aOrderDetailBean.getGs_is_prov_balanced() != null){
			tSql.append(",GS_IS_PROV_BALANCEED='" + aOrderDetailBean.getGs_is_prov_balanced() + "'");
		}
		if(aOrderDetailBean.getGs_cancel_cause() != null){
			tSql.append(",GS_CANCEL_CAUSE='" + aOrderDetailBean.getGs_cancel_cause()+"'");
		}
		if(aOrderDetailBean.getGs_cancel_date() != null){
			tSql.append(",GS_CANCEL_DATE='" + aOrderDetailBean.getGs_cancel_date() + "'");
		}
		if(aOrderDetailBean.getGs_cancel_person() != null){
			tSql.append(",GS_CANCEL_PERSON='" + aOrderDetailBean.getGs_cancel_person() + "'");
		}
		tSql.append(",GS_BALANCE_MONTH='" + aOrderDetailBean.getGs_balance_month() + "'");
		tSql.append(",GS_BALANCE_MONTH_PROVIDER='" + aOrderDetailBean.getGs_balance_month_provider() + "'");
		//add 2006-4-24 for balance
		tSql.append(" where GS_ORDER_DETAIL_ID='" + aOrderDetailBean.getGs_order_detail_id() + "' ");

		if(aOldStatus != null) {
			if(aOldStatus == GSBaseConstants.ORDER_ORDERING)
			{
				tSql.append("and (GS_ORDER_DETAIL_STATUS = '" + aOldStatus + "' or GS_ORDER_DETAIL_STATUS = '" + GSBaseConstants.ORDER_ORDER_CONFIRM + "')");
			}else if(aOldStatus == GSBaseConstants.ORDER_BLANK_OUT) //add by Sindy 2007-10-29
			{
			}else{
				tSql.append("and GS_ORDER_DETAIL_STATUS = '" + aOldStatus + "'");
			}
		} else {
			tSql.append(" and GS_ORDER_DETAIL_STATUS IS NULL");
		}

		GSLogWriter.debug(this,"Sql=" + tSql.toString());
		boolean tFlag = false;
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19994,GSException.E19994_MSG);
		}
		return tFlag;
	}
	
	/**
	 * 查询订单明细状态为订货中，订货确认的订单明细
	 * @param aConn                 DB连接
	 * @param aOrderDtlModVO        查询参数VO
	 * @param aOrg                  可查询组织
	 * @param pageNo                页号
	 * @param pageSize              页大小（每页可显示笔数）
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetailForMod(Connection aConn,GSOrderDetailModifyVO aOrderDtlModVO,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer(getSqlForOrderDetailMod(aOrderDtlModVO));
		tSql.append(" order by det.GS_LASTMODIFY_DATE desc");
		GSLogWriter.debug(this,tSql.toString());
		ArrayList tList = new ArrayList();
		Object tObj[] = {};
		try{
			tList = this.executeQuery(aConn,new GSOrderAnaDetailAndCategoryBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);

		}
		return tList;
	}


	/**
	 * 查询维护管理所有的订单明细
	 * @param aConn                 DB连接
	 * @param aOrderDtlModVO        查询参数VO
	 * @param aOrg                  可查询组织
	 * @param pageNo                页号
	 * @param pageSize              页大小（每页可显示笔数）
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryManagerOrderForMod(Connection aConn,GSOrderDetailModifyVO aOrderDtlModVO,ArrayList aOrg,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer(getSqlForManagerOrderMod(aOrderDtlModVO,aOrg));
		tSql.append(" order by a.GS_LASTMODIFY_DATE desc");
		GSLogWriter.debug(this,tSql.toString());
		ArrayList tList = new ArrayList();
		Object tObj[] = {};
		try{
			tList = this.executeQuery(aConn,new GSOrderDetailModifyVO(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);

		}
		return tList;
	}


	/**
	 * 查询可修改订单明细的笔数
	 * @param aOrderDtlModVO        查询参数VO
	 * @param aOrg                  可查询组织
	 * @return
	 * @throws GSException
	 */
	public int queryOrderDetailCountForMod(GSOrderDetailModifyVO aOrderDtlModVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getSqlForOrderDetailMod(aOrderDtlModVO));
		tSql.append(")");
		Object[] tObj = {};
		int tSize = 0;
		try{
			tSize = queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19993,GSException.E19993_MSG);
		}
		return tSize;
	}

	/**
	 * 查询维护管理可修改订单明细的笔数
	 * @param aOrderDtlModVO        查询参数VO
	 * @param aOrg                  可查询组织
	 * @return
	 * @throws GSException
	 */
	public int queryManagerOrderCountForMod(GSOrderDetailModifyVO aOrderDtlModVO,ArrayList aOrg) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getSqlForManagerOrderMod(aOrderDtlModVO,aOrg));
		tSql.append(")");
		Object[] tObj = {};
		int tSize = 0;
		try{
			tSize = queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19993,GSException.E19993_MSG);
		}
		return tSize;
	}

	/**
	 * 组装查询可更改订单信息的SQL
	 * @param aVO               查询参数
	 * @param aOrg              可查询组织
	 * @return
	 * @throws GSException
	 */
	private String getSqlForOrderDetailMod(GSOrderDetailModifyVO aVO) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderAndDetailAndCategorySql());
		if(aVO.orderCreateDateStr != null  && aVO.orderCreateDateStr.trim().length()!= 0) {
			tSql.append(" and ord.GS_ORDER_CREATE_DATE  >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		}
		if(aVO.orderCreateDateEnd != null  && aVO.orderCreateDateEnd.trim().length()!= 0) {
			tSql.append(" and ord.GS_ORDER_CREATE_DATE  <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		}
		if(aVO.orderDetailId != null && !aVO.orderDetailId.equals("")){
			tSql.append(" and det.GS_ORDER_DETAIL_ID like '%"+ aVO.orderDetailId + "%'");
		}
		if(aVO.providerName != null && !aVO.providerName.equals("")){
			tSql.append(" and (prv.NAME ='"+ aVO.providerName + "'");
			tSql.append(" or prv.FULL_NAME='" + aVO.providerName + "')");
		}
		if(aVO.orderDeptId!=null){
			tSql.append(" and ord.GS_WORKCORP_ID like '" + aVO.orderDeptId + "%'");
		}
		if(aVO.concentricityId != null && !aVO.concentricityId.trim().equals("")){
			tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + aVO.concentricityId + "%'");
		}
		if(aVO.orderDetailStatus.equals("0000")){
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS in ('7','9')");
		}else{
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS ='" + aVO.orderDetailStatus + "'");
		}
		if(aVO.manufInfo != null && aVO.manufInfo.trim().length() != 0){
			tSql.append(" and (pro.NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.MODEL like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.PRODUCT_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.MANUFATURER like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manufType1!= null && aVO.manufType1.trim().length() != 0){
			if(aVO.manufType1.equals("0")){
				tSql.append(" and cat.code like '%'");

			}else if(aVO.manufType2.equals("0")){

				tSql.append(" and (cat.CATEGORY_ID1 ='" + aVO.manufType1 + "'");

				tSql.append(" or cat.code='" + aVO.manufType1 + "')");
			}else if(aVO.manufType3.equals("0")){

				tSql.append(" and (cat.CATEGORY_ID2 ='" + aVO.manufType2 + "'");

				tSql.append(" or cat.code='" + aVO.manufType2 + "')");
			}else{
				tSql.append(" and cat.code ='" + aVO.manufType3 + "'");
			}
		}

		//图件号
		if(aVO.drawingpiececode != null && !aVO.drawingpiececode.equals("")){
			tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + aVO.drawingpiececode.trim() + "%'");
		}
		return tSql.toString();
	}

	/**
	 * 组装查询维护管理可更改订单信息的SQL
	 * @param aVO               查询参数
	 * @param aOrg              可查询组织
	 * @return
	 * @throws GSException
	 */
	private String getSqlForManagerOrderMod(GSOrderDetailModifyVO aVO,ArrayList aOrg) throws GSException{
		if(aOrg == null){
			aOrg =new ArrayList();
			String[] tTmpOrg ={"NoOrg"};
			aOrg.add(tTmpOrg);
		}
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,a.GS_DELIVER_GOODS_DATE as P13,a.GS_DELIVER_GOODS_TIME as P14,a.GS_ORDER_TEMPID as P15,");
		tSql.append("d.GS_PROVIDER_ID as P16,a.GS_ORDER_DETAIL_STATUS as P17,d.GS_IS_TRADEFLAT_PROVIDER as P18,a.GS_LASTMODIFY_DATE");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e,GS_ORDER_DEPT_INFO f,");
		tSql.append(" GS_MANUFACTURE_CATEGORY g");
		tSql.append(" where e.GS_ORDER_TEMPID = a.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID");
		tSql.append(" and e.GS_DELIVER_GOODS_ADDR=f.GS_DELIVER_GOODS_ADDR");
		if(aVO.orderCreateDateStr != null  && aVO.orderCreateDateStr.trim().length()!= 0) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		}
		if(aVO.orderCreateDateEnd != null && aVO.orderCreateDateEnd.trim().length() != 0) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		}

		tSql.append(" and b.GS_MANUFACTURE_CATEGORY_ID = g.GS_MANUFACTURE_CATEGORY_ID");

		if(aVO.orderDetailId != null && aVO.orderDetailId.trim().length() != 0){
			tSql.append(" and a.GS_ORDER_DETAIL_ID like '%"+ aVO.orderDetailId + "%'");
		}
		if(aVO.providerName != null && aVO.providerName.trim().length() != 0){
			tSql.append(" and (d.GS_PROVIDER_NAME ='"+ aVO.providerName + "'");
			tSql.append(" or d.GS_PROVIDER_SHORTNAME='" + aVO.providerName + "')");
		}
		if(!aVO.orderDeptId.equals("0000")){
			tSql.append(" and e.GS_WORKCORP_ID = '" + aVO.orderDeptId + "'");
		}else{
			if(aOrg.size() > 0){
				tSql.append(" and e.GS_WORKCORP_ID in(");
				for(int i=0; i<aOrg.size();i++){
					String tStr[] = (String[])aOrg.get(i);
					if( i == aOrg.size()-1){
						tSql.append("'"+tStr[0]+"')");
					}else{
						tSql.append("'"+tStr[0]+"',");
					}
				}
			}
		}
		if(!aVO.deliverGoodsAddrId.equals("0000")){
			tSql.append(" and f.GS_DELIVER_GOODS_ADDR_ID ='" + aVO.deliverGoodsAddrId + "'");
		}
		if(aVO.concentricityId != null && !aVO.concentricityId.trim().equals("")){
			tSql.append(" and a.GS_CONCENTRICITY_ID like '" + aVO.concentricityId + "'");
		}
		if(aVO.orderDetailStatus.equals("0000")){
		}else{
			tSql.append(" and a.GS_ORDER_DETAIL_STATUS ='" + aVO.orderDetailStatus + "'");
		}
		if(aVO.manufInfo != null &&aVO.manufInfo.trim().length() != 0){
			tSql.append(" and (b.GS_MANUFACTURE_NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_TYPE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURER_NAME like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manufType1!= null && aVO.manufType1.trim().length() != 0){
			if(aVO.manufType1.equals("0")){
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID like '%'");

			}else if(aVO.manufType2.equals("0")){

				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID1 ='" + aVO.manufType1 + "'");

				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType1 + "')");
			}else if(aVO.manufType3.equals("0")){

				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID2 ='" + aVO.manufType2 + "'");

				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType2 + "')");
			}else{
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID ='" + aVO.manufType3 + "'");
			}
		}
		return tSql.toString();
	}


	/**
	 * 修改订单明细状态为订货中，订货确认的订单明细
	 * @param aConn                 DB连接
	 * @param aOrderDetailBean      订单明细bean对象
	 * @return
	 * @throws GSException
	 */
	public boolean updateOrderDetail(Connection aConn,GSOrderAnaDetailAndCategoryBean aOrderDetailBean) throws GSException{
		boolean tFlag = false;
		Object[] tObj = new Object[11];
		try{
			StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_PROVIDER_ID=?,GS_MANUFACTURE_ID=?,");
			tSql.append("GS_GOODS_UNITPRICE=?,GS_DELIVER_GOODS_DATE=?,GS_DELIVER_GOODS_TIME=?,GS_ORDER_COUNT=?,");
			tSql.append("GS_LASTMODIFER_ID=?,GS_LASTMODIFY_CONTENTS=?,GS_LASTMODIFY_DATE=?,gs_balance_mode=? ");
			tSql.append("where GS_ORDER_DETAIL_ID=?");
			tObj[0] = aOrderDetailBean.getGs_provider_id();
			tObj[1] = aOrderDetailBean.getGs_manufacture_id();
			tObj[2] = new Double(aOrderDetailBean.getGs_goods_unitprice());
			tObj[3] = aOrderDetailBean.getGs_deliver_goods_date();
			tObj[4] = aOrderDetailBean.getGs_deliver_goods_time();
			tObj[5] = new Double(aOrderDetailBean.getGs_order_count());
			tObj[6] = aOrderDetailBean.getGs_lastmodifer_id();
			tObj[7] = aOrderDetailBean.getGs_lastmodify_contents();
			tObj[8] = DateUtil.formateDateTime(DateUtil.getCurrentTime("DT","AD"));
			tObj[9]=aOrderDetailBean.getGs_balance_mode();
			tObj[10] = aOrderDetailBean.getGs_order_detail_id();

			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19994,GSException.E19994_MSG);
		}
		return tFlag;
	}

	/**
	 * 查询手工处理订单及明细信息
	 * @param aGSOrderVO        查询参数
	 * @param aOrg              可查询组织
	 * @param pageNo            页号
	 * @param pageSize          页大小（显示笔数）
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryUncommitOrderInfoForNonFlatsdProv(GSOrderSubmitForNonFlatVO aGSOrderVO,int pageNo,int pageSize) throws GSException{
		ArrayList tList = new ArrayList();
		StringBuffer tSql = new StringBuffer(getSqlForOrderSubmitOfsdNonFlat(aGSOrderVO));
		tSql.append(" order by det.GS_LASTMODIFY_DATE desc");

		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderAnaDetailAndCategoryBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询非网上订单及明细信息
	 * @param aGSOrderVO        查询参数
	 * @param aOrg              可查询组织
	 * @param pageNo            页号
	 * @param pageSize          页大小（显示笔数）
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryUncommitOrderInfoForNonFlatProv(GSOrderSubmitForNonFlatVO aGSOrderVO,ArrayList aOrg,int pageNo,int pageSize) throws GSException{
		ArrayList tList = new ArrayList();
		StringBuffer tSql = new StringBuffer(getSqlForOrderSubmitOfNonFlat(aGSOrderVO,aOrg));
		tSql.append(" order by a.GS_LASTMODIFY_DATE desc");

		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderSubmitForNonFlatVO(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询非网上订单笔数
	 * @param aGSOrderVO
	 * @param aOrg
	 * @return
	 * @throws GSException
	 */
	public int queryOrderCountForNonFlatProv(GSOrderSubmitForNonFlatVO aGSOrderVO,ArrayList aOrg) throws GSException{
		int tSize = 0;
		StringBuffer tSql = new StringBuffer("select count(*) from (");
		tSql.append(getSqlForOrderSubmitOfNonFlat(aGSOrderVO,aOrg));
		tSql.append(")");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tSize = queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}


	/**
	 * 查询手工处理订单笔数
	 * @param aGSOrderVO
	 * @param aOrg
	 * @return
	 * @throws GSException
	 */
	public int queryOrderCountForNonFlatsdProv(GSOrderSubmitForNonFlatVO aGSOrderVO) throws GSException{
		int tSize = 0;
		StringBuffer tSql = new StringBuffer("select count(*) from (");
		tSql.append(getSqlForOrderSubmitOfsdNonFlat(aGSOrderVO));
		tSql.append(")");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tSize = queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}
	/**
	 * 组装查询非网上订单SQL
	 * @param aVO           查询参数VO
	 * @param aOrg          可查询组织
	 * @return
	 * @throws GSException
	 */
	private String getSqlForOrderSubmitOfNonFlat(GSOrderSubmitForNonFlatVO aVO,ArrayList aOrg) throws GSException{
		if(aOrg == null){
			aOrg =new ArrayList();
			String[] tTmpOrg ={"NoOrg"};
			aOrg.add(tTmpOrg);
		}
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,a.GS_DELIVER_GOODS_DATE as P13,a.GS_DELIVER_GOODS_TIME as P14,a.GS_ORDER_TEMPID as P15,");
		tSql.append("d.GS_PROVIDER_ID as P16,a.GS_ORDER_DETAIL_STATUS as P17,a.GS_LASTMODIFY_DATE,b.GS_APPENDER_PROPERTY as P18,a.gs_balance_mode P19,");
		tSql.append("a.GS_MANUFACTURE_ID as P20,d.GS_IS_TRADEFLAT_PROVIDER as P21");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e,GS_ORDER_DEPT_INFO f,");
		tSql.append(" GS_MANUFACTURE_CATEGORY g ");
		tSql.append(" where e.GS_ORDER_TEMPID = a.GS_ORDER_TEMPID and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID");
		tSql.append(" and (d.GS_IS_TRADEFLAT_PROVIDER ='1' or b.GS_IS_TRADEFLAT_MANUFACTURE = '2')");
		tSql.append(" and e.GS_DELIVER_GOODS_ADDR=f.GS_DELIVER_GOODS_ADDR");
		tSql.append(" and e.GS_ORDER_CREATE_DATE >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		tSql.append(" and e.GS_ORDER_CREATE_DATE <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		tSql.append(" and b.GS_MANUFACTURE_CATEGORY_ID = g.GS_MANUFACTURE_CATEGORY_ID");
		if(aVO.orderDetailId != null && !aVO.orderDetailId.equals("")){
			tSql.append(" and a.GS_ORDER_DETAIL_ID ='"+ aVO.orderDetailId + "'");
		}
		if(aVO.providerName != null && !aVO.providerName.equals("")){
			tSql.append(" and (d.GS_PROVIDER_NAME ='"+ aVO.providerName + "'");
			tSql.append(" or d.GS_PROVIDER_SHORTNAME='" + aVO.providerName + "')");
		}
		if(!aVO.orderDeptId.equals("0000")){
			tSql.append(" and e.GS_WORKCORP_ID = '" + aVO.orderDeptId + "'");
		}else{
			if(aOrg != null && aOrg.size() > 0){
				tSql.append(" and e.GS_WORKCORP_ID in(");
				for(int i=0; i<aOrg.size();i++){
					String tStr[] = (String[])aOrg.get(i);
					if( i == aOrg.size()-1){
						tSql.append("'"+tStr[0]+"')");
					}else{
						tSql.append("'"+tStr[0]+"',");
					}
				}
			}
		}
		if(!aVO.deliverGoodsAddr.equals("0000")){
			tSql.append(" and f.GS_DELIVER_GOODS_ADDR_ID ='" + aVO.deliverGoodsAddr + "'");
		}
		if(aVO.concentricityId != null && !aVO.concentricityId.trim().equals("")){
			tSql.append(" and a.GS_CONCENTRICITY_ID like '%" + aVO.concentricityId + "%'");
		}
		if(aVO.orderDetailStatus.equals("0000")){
			tSql.append(" and a.GS_ORDER_DETAIL_STATUS in ('7','9','10')");
		}else{
			tSql.append(" and a.GS_ORDER_DETAIL_STATUS ='" + aVO.orderDetailStatus + "'");
		}
		if(aVO.manufInfo != null){
			tSql.append(" and (b.GS_MANUFACTURE_NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_TYPE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURER_NAME like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manufType1!= null){
			if(aVO.manufType1.equals("0")){
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID like '%'");
			}else if(aVO.manufType2.equals("0")){
				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID1 ='" + aVO.manufType1 + "'");
				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType1 + "')");
			}else if(aVO.manufType3.equals("0")){
				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID2 ='" + aVO.manufType2 + "'");
				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType2 + "')");
			}else{
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID ='" + aVO.manufType3 + "'");
			}
		}
		return tSql.toString();
	}
	/**
	 * 运营公司级申购综合查询订单
	 * @param aGSOrderVO        传入的查询参数VO对象
	 * @param aOrg              可查询订货单位ArrayList对象
	 * @param pageNo            页号
	 * @param pageSize          页大小
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetailByOpt(GSOrderVO aGSOrderVO,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderDetailByOptSql(aGSOrderVO));
		tSql.append(" order by det.GS_DELIVER_GOODS_DATE desc,det.GS_DELIVER_GOODS_TIME desc");
		ArrayList tList = new ArrayList();
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderAnaDetailBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 运营公司级申购综合查询订单笔数
	 * @param aGSOrderVO    查询参数封装VO
	 * @param aOrg          可查询订货单位对象
	 * @return
	 * @throws GSException
	 */
	public int queryOrderDetailCountByOpt(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getOrderDetailByOptSql(aGSOrderVO));
		tSql.append(")");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		int size = 0;
		try{
			size = this.queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return size;
	}
	/**
	 * 运营公司级申购综合查询订单SQL
	 * @param aGSOrderVO        查询参数封装VO
	 * @param aOrg              可查询订货单位对象
	 * @return
	 * @throws GSException
	 */
	private String getOrderDetailByOptSql(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderAndDetailSql());

		if(aGSOrderVO.orderCreateDateLowLimie !=null && aGSOrderVO.orderCreateDateLowLimie.trim().length() != 0){
			tSql.append(" and det.gs_deliver_goods_date >='" + aGSOrderVO.orderCreateDateLowLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(6,8) + "'");
		}
		if(aGSOrderVO.orderCreateDateUprLimie !=null &&  aGSOrderVO.orderCreateDateUprLimie.trim().length() != 0){
			tSql.append(" and det.gs_deliver_goods_date <='" + aGSOrderVO.orderCreateDateUprLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(6,8) + "'");
		}


		if(aGSOrderVO.orderid != null && aGSOrderVO.orderid.trim().length()!=0){
			tSql.append(" and ord.GS_ORDER_TEMPID like '" + aGSOrderVO.orderid + "'");
		}

		if(aGSOrderVO.drawingpiececode != null && !aGSOrderVO.drawingpiececode.equals("")){
			tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + aGSOrderVO.drawingpiececode.trim() + "%'");
		}

		if(!aGSOrderVO.orderDetailStatus.equals("0000")){
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS = '" + aGSOrderVO.orderDetailStatus + "'");
		}
		if(aGSOrderVO.orderDeptId!=null){
			tSql.append(" and ord.GS_WORKCORP_ID like '" + aGSOrderVO.orderDeptId + "%'");
		}
		if(aGSOrderVO.concentricityId != null && aGSOrderVO.concentricityId.trim().length()!=0){
			tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + aGSOrderVO.concentricityId + "%'");
		}
		if(aGSOrderVO.manufInfo != null && aGSOrderVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (pro.NAME like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MODEL like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.SPEC like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.PRODUCT_BRAND like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.APPENDER_PROPERTY like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MANUFATURER like '%" + aGSOrderVO.manufInfo + "%')");
		}
		return tSql.toString();
	}

	/**
	 * 运营公司级申购综合查询订单SQL
	 * @param aGSOrderVO        查询参数封装VO
	 * @param aOrg              可查询订货单位对象
	 * @return
	 * @throws GSException
	 */
	private String getOrderDetailByOptSql_r(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderAndDetailSql());

		if(aGSOrderVO.orderCreateDateLowLimie !=null && aGSOrderVO.orderCreateDateLowLimie.trim().length() != 0){
			tSql.append(" and det.gs_deliver_goods_date >='" + aGSOrderVO.orderCreateDateLowLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(6,8) + "'");
		}
		if(aGSOrderVO.orderCreateDateUprLimie !=null &&  aGSOrderVO.orderCreateDateUprLimie.trim().length() != 0){
			tSql.append(" and det.gs_deliver_goods_date <='" + aGSOrderVO.orderCreateDateUprLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(6,8) + "'");
		}

		if(aGSOrderVO.orderDetailId!=null&&aGSOrderVO.orderDetailId.trim().length()!=0){
			tSql.append(" and det.GS_ORDER_detail_id like '" + aGSOrderVO.orderDetailId + "%'");
		}
		if(aGSOrderVO.drawingpcode != null && aGSOrderVO.drawingpcode.trim().length()!=0){
			tSql.append(" and pro.drawing_piece_code like '%" + aGSOrderVO.drawingpcode + "%'");
		}

		if(!aGSOrderVO.orderDetailStatus.equals("0000")){
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS = '" + aGSOrderVO.orderDetailStatus + "'");
		}
		if(aGSOrderVO.orderDeptId!=null){
			tSql.append(" and ord.GS_WORKCORP_ID like '" + aGSOrderVO.orderDeptId + "%'");
		}
		if(aGSOrderVO.concentricityId != null && aGSOrderVO.concentricityId.trim().length()!=0){
			tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + aGSOrderVO.concentricityId + "%'");
		}
		if(aGSOrderVO.providerName!=null&&aGSOrderVO.providerName.trim().length()!=0){
			tSql.append(" and prv.name like '%" + aGSOrderVO.providerName + "%'");
		}

		if (aGSOrderVO.deliverGoodsId!=null&&aGSOrderVO.deliverGoodsId.trim().length()!=0) {
			tSql.append(" and det.gs_deliver_goods_id like '%" + aGSOrderVO.deliverGoodsId + "%'");
		}

		if(aGSOrderVO.manufInfo != null && aGSOrderVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (pro.NAME like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MODEL like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.SPEC like '%"  + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.PRODUCT_BRAND like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.APPENDER_PROPERTY like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MANUFATURER like '%" + aGSOrderVO.manufInfo + "%')");
		}
		return tSql.toString();
	}
	/**
	 * 采购跟踪查询订单信息
	 * @param aGSOrderVO    查询参数封装VO
	 * @param aOrg          可查询订货单位对象
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetailForStatusTrace(GSOrderVO aGSOrderVO,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer();
		tSql.append(getOrderDtlSqlForStatusTrace(aGSOrderVO));
		//tSql.append(" order by B.GS_LASTMODIFY_DATE desc");
		tSql.append(" order by det.GS_DELIVER_GOODS_DATE desc,det.GS_DELIVER_GOODS_TIME desc");
		GSLogWriter.debug(this,tSql.toString());
		ArrayList tList = new ArrayList();
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderAnaDetailBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	private String getOrderDtlSqlForStatusTrace(GSOrderVO aGSOrderVO)throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderAndDetailSql());
		tSql.append(" and det.GS_ORDER_DETAIL_ID in ( select GS_ORDER_DETAIL_ID from GS_ORDER_DETAIL where 1=1 ");

		if(aGSOrderVO.orderCreateDateLowLimie !=null && !"".equals(aGSOrderVO.orderCreateDateLowLimie)){
			tSql.append(" and det.GS_DELIVER_GOODS_DATE >='" + aGSOrderVO.orderCreateDateLowLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateLowLimie.substring(6,8) + "'");
		}
		if(aGSOrderVO.orderCreateDateUprLimie !=null && !"".equals(aGSOrderVO.orderCreateDateUprLimie)){
			tSql.append(" and det.GS_DELIVER_GOODS_DATE <='" + aGSOrderVO.orderCreateDateUprLimie.substring(0,4)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(4,6)+"-"+aGSOrderVO.orderCreateDateUprLimie.substring(6,8) + "'");
		}

		tSql.append(" )");

		if(aGSOrderVO.orderid != null && aGSOrderVO.orderid.trim().length() != 0){
			tSql.append(" and ord.GS_ORDER_TEMPID = '" + aGSOrderVO.orderid + "'");
		}
		if(aGSOrderVO.orderDetailId != null && aGSOrderVO.orderDetailId.trim().length() != 0){
			tSql.append(" and det.GS_ORDER_DETAIL_ID ='" + aGSOrderVO.orderDetailId+"'");
		}
		if(!aGSOrderVO.orderDetailStatus.equals("0000")){
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS = '" + aGSOrderVO.orderDetailStatus + "'");
		}else {
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS in('6','7','8','9','10','11','22')");
		}
		if(aGSOrderVO.orderDeptId!=null){
			tSql.append(" and ord.GS_WORKCORP_ID like '" + aGSOrderVO.orderDeptId + "%'");
		}
		if(aGSOrderVO.concentricityId != null && aGSOrderVO.concentricityId.trim().length()!= 0){
			tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + aGSOrderVO.concentricityId + "%'");
		}
		//图件号
		if(aGSOrderVO.drawingpiececode != null && !aGSOrderVO.drawingpiececode.equals("")){
			tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + aGSOrderVO.drawingpiececode.trim() + "%'");
		}
		if(aGSOrderVO.manufInfo != null && aGSOrderVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (pro.NAME like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MODEL like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.SPEC like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.PRODUCT_BRAND like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.APPENDER_PROPERTY like '%" + aGSOrderVO.manufInfo + "%'");
			tSql.append(" or pro.MANUFATURER like '%" + aGSOrderVO.manufInfo +"%')");
		}
		return tSql.toString();
	}
	public int queryOrderDtlCountForStatusTrace(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from (");
		tSql.append(getOrderDtlSqlForStatusTrace(aGSOrderVO));
		tSql.append(")");
		int tSize = 0;
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tSize = this.queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}






	/**
	 * 组装查询非网上订单SQL
	 * @param aVO           查询参数VO
	 * @param aOrg          可查询组织
	 * @return
	 * @throws GSException
	 */
	private String getSqlForOrderSubmitOfsdNonFlat(GSOrderSubmitForNonFlatVO aVO) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderAndDetailAndCategorySql());
		tSql.append(" and det.GS_ORDERRETURN_SIGN not in ('"+GSBaseConstants.APEP_RETURN_SIGN_SUCCESS+"','-1')");
		tSql.append(" and ord.GS_ORDER_CREATE_DATE >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		tSql.append(" and ord.GS_ORDER_CREATE_DATE <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		if(aVO.orderDetailId != null && !aVO.orderDetailId.equals("")){
			tSql.append(" and det.GS_ORDER_DETAIL_ID ='"+ aVO.orderDetailId + "'");
		}
		if(aVO.providerName != null && !aVO.providerName.equals("")){
			tSql.append(" and (prv.NAME ='"+ aVO.providerName + "'");
			tSql.append(" or prv.GS_PROVIDER_SHORTNAME='" + aVO.providerName + "')");
		}
		if(aVO.orderDeptId!=null){
			tSql.append(" and ord.GS_WORKCORP_ID like '" + aVO.orderDeptId + "%'");
		}
		if(aVO.concentricityId != null && !aVO.concentricityId.trim().equals("")){
			tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + aVO.concentricityId + "%'");
		}
		if(aVO.orderDetailStatus.equals("0000")){
			if(aVO.chk!=null){
				tSql.append(" and det.GS_ORDER_DETAIL_STATUS in ('3','6','7')");
			}else{
				tSql.append(" and det.GS_ORDER_DETAIL_STATUS in ('3','6','7','9','10')");
			}
		}else{
			tSql.append(" and det.GS_ORDER_DETAIL_STATUS ='" + aVO.orderDetailStatus + "'");
		}
		if(aVO.manufInfo != null){
			tSql.append(" and (pro.NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.MODEL like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.PRODUCT_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or pro.MANUFATURER like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manufType1!= null){
			if(aVO.manufType1.equals("0")){
				tSql.append(" and cat.code like '%'");
			}else if(aVO.manufType2.equals("0")){
				tSql.append(" and (cat.CATEGORY_ID1 ='" + aVO.manufType1 + "'");
				tSql.append(" or cat.code='" + aVO.manufType1 + "')");
			}else if(aVO.manufType3.equals("0")){
				tSql.append(" and (cat.CATEGORY_ID2 ='" + aVO.manufType2 + "'");
				tSql.append(" or cat.code='" + aVO.manufType2 + "')");
			}else{
				tSql.append(" and cat.code ='" + aVO.manufType3 + "'");
			}
		}

		//图件号
		if(aVO.drawingpiececode != null && !aVO.drawingpiececode.equals("")){
			tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + aVO.drawingpiececode.trim() + "%'");
		}
		return tSql.toString();
	}


	/**
	 * 修改某笔订单中所有订单明细的状态
	 * @param aConn             DB连接
	 * @param aOrderDetail      订单明细对象
	 * @param aOldStatus        原状态
	 * @return                  成功返回true，失败返回false
	 * @throws GSException
	 */
	public boolean updateDetailStatusByOrderId(Connection aConn,GSOrderDetailBean aOrderDetail,String aOldStatus)throws GSException{
		boolean tFlag = false;
		String tSql = "update GS_ORDER_DETAIL set GS_ORDER_DETAIL_STATUS=?,GS_LASTMODIFER_ID=?,GS_LASTMODIFY_CONTENTS=?,GS_LASTMODIFY_DATE=?" +
		" where GS_ORDER_TEMPID=? and RTRIM(GS_ORDER_DETAIL_STATUS,' ')=?";
		Object tObj[] = new Object[6];
		tObj[0] = aOrderDetail.getGs_order_detail_status();
		tObj[1] = aOrderDetail.getGs_lastmodifer_id();
		tObj[2] = aOrderDetail.getGs_lastmodify_contents();
		tObj[3] = aOrderDetail.getGs_lastmodify_date();
		tObj[4] = aOrderDetail.getGs_order_temp_id();
		tObj[5] = aOldStatus;
		try{
			tFlag = this.executeUpdate(aConn,tSql,tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19995,GSException.E19995_MSG);
		}
		return tFlag;
	}

	public static void main(String[] arg){
		GSOrderDetailDAO tDAO = new GSOrderDetailDAO();
		try{
			String temp = tDAO.queryOrderDetailByDetailId("10000006").getGs_order_detail_status();
			System.out.println("=1==" + temp);
			if(temp.equals("")){
				System.out.println("true");
			}else{
				System.out.println("false");
			}
			System.out.println("=2==" + temp.length());
		}catch(Exception e){
			e.printStackTrace();
		}finally{

		}
	}
	/**
	 * 查询订单明细
	 * @param tSql              查询SQL
	 * @param aBaseBean         基类Bean
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetail(String tSql,GSBaseBean aBaseBean) throws GSException{
		ArrayList tList = new ArrayList();
		Object[] tObj = {};
		try{
			tList = this.executeQuery(aBaseBean,tSql,tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);

		}
		return tList;
	}

	/**
	 * 应急采购查询订单信息
	 * @param aOrderId      订单编号
	 * @return
	 * @throws GSException
	 */
	public ArrayList EmergencyOrderQueryDetail(String aOrderId) throws GSException{

		ArrayList tList = new ArrayList();

		StringBuffer tSql = new StringBuffer("select a.GS_CONCENTRICITY_ID as P1,a.GS_MANUFACTURE_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_MANUFACTURE_SPEC as P4,b.GS_MANUFACTURE_TYPE as P5,b.GS_MANUFACTURE_BRAND as P6,a.GS_ORDER_COUNT as P7,");
		tSql.append("a.GS_SIGNIN_COUNT as P8,b.GS_QUANT_UNIT as P9,a.GS_GOODS_UNITPRICE as P10,a.GS_SIGNIN_PRICE as P11,");
		tSql.append("b.GS_PROVIDER_ID as P12,a.GS_ORDER_TEMPID as P13,a.GS_ORDER_DETAIL_ID as p14 ");

		tSql.append("from GS_ORDER_TEMP_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c ");

		tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID ");
		tSql.append("and ((a.GS_MANUFACTURE_ID is NOT NULL and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID)");
		tSql.append(" or a.GS_MANUFACTURE_ID IS NULL) ");
		tSql.append("and a.GS_WORKCORP_ID=c.GS_ORG_ID ");
		//tSql.append("order by a.GS_LASTMODIFY_DATE desc");
		Object[] tObj = {aOrderId};
		try{
			tList = executeQuery(new GSEmergencyOrderDetailVO(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 应急采购信息插入订单明细表
	 * @param aOrderDtlBean         订单明细Bean对象
	 * @param aConn                 DB连接
	 * @return
	 * @throws GSException
	 */
	public boolean insertOrderDetailFromTemp(GSOrderDetailBean aOrderDtlBean,Connection aConn) throws GSException{
		boolean tFlag = false;
		StringBuffer tSql = new StringBuffer("insert into GS_ORDER_DETAIL(GS_ORDER_TEMPID,GS_ORDER_DETAIL_ID,GS_ORDER_DETAIL_STATUS,");
		tSql.append("GS_CONCENTRICITY_ID,GS_MANUFACTURE_ID,GS_ORDER_COUNT,GS_PROVIDER_ID,");
		tSql.append("GS_DELIVER_GOODS_ID,GS_GOODS_UNITPRICE,GS_DELIVERYMAN,GS_DELIVER_GOODS_PHONE,");
		tSql.append("GS_SIGNIN_DATE,GS_SIGNIN_TIME,GS_SIGNIN_PERSON,GS_SIGNIN_EXPLAIN,");
		tSql.append("GS_SIGNIN_COUNT,GS_LASTMODIFER_ID,GS_LASTMODIFY_CONTENTS,GS_LASTMODIFY_DATE,");
		tSql.append("GS_IS_BALANCEED,GS_DELIVER_GOODS_COUNTS,GS_DELIVER_GOODS_DATE,GS_DELIVER_GOODS_TIME,GS_IS_PROV_BALANCEED)values(");
		tSql.append("?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		Object[] tObj = new Object[24];
		tObj[0] = aOrderDtlBean.getGs_order_temp_id();
		tObj[1] = aOrderDtlBean.getGs_order_detail_id();
		tObj[2] = aOrderDtlBean.getGs_order_detail_status();
		tObj[3] = aOrderDtlBean.getGs_concentricity_id();
		tObj[4] = aOrderDtlBean.getGs_manufacture_id();
		tObj[5] = String.valueOf(aOrderDtlBean.getGs_order_count());
		tObj[6] = aOrderDtlBean.getGs_provider_id();
		tObj[7] = aOrderDtlBean.getGs_deliver_goods_id();
		tObj[8] = new Double(aOrderDtlBean.getGs_goods_unitprice());
		tObj[9] = aOrderDtlBean.getGs_deliveryman();
		tObj[10] = aOrderDtlBean.getGs_deliver_goods_phone();
		tObj[11] = aOrderDtlBean.getGs_signin_date();
		tObj[12] = aOrderDtlBean.getGs_signin_time();
		tObj[13] = aOrderDtlBean.getGs_signin_person();
		tObj[14] = aOrderDtlBean.getGs_signin_explain();
		tObj[15] = new Double(aOrderDtlBean.getGs_signin_count());
		tObj[16] = aOrderDtlBean.getGs_lastmodifer_id();
		tObj[17] = aOrderDtlBean.getGs_lastmodify_contents();
		tObj[18] = DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss");
		tObj[19] = aOrderDtlBean.getGs_is_balanced();
		tObj[20] = String.valueOf(aOrderDtlBean.getGs_deliver_goods_counts());
		tObj[21] = aOrderDtlBean.getGs_deliver_goods_date();
		tObj[22] = aOrderDtlBean.getGs_deliver_goods_time();
		tObj[23] = aOrderDtlBean.getGs_is_balanced();
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19995,GSException.E19995_MSG);
		}
		return tFlag;
	}
	/**
	 * 根据订货单位和结算截至日期查询未结算订单明细
	 * @param aOrderDeptId			订货单位编码
	 * @param aBalanceYM			结算截至日期
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryUnBalanceDetail(String aOrderDeptId,String aBalanceYM) throws GSException{
		StringBuffer tSql = new StringBuffer("select A.* from GS_ORDER_DETAIL A ,GS_ORDER B where A.GS_IS_BALANCEED='0'");
		tSql.append(" and A.GS_ORDER_DETAIL_STATUS='12'");
		tSql.append(" and to_char(to_date(A.GS_SIGNIN_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <=?");
		tSql.append(" and A.GS_ORDER_TEMPID=B.GS_ORDER_TEMPID");
		tSql.append(" and B.GS_WORKCORP_ID=? order by A.GS_PROVIDER_ID");
		GSLogWriter.info(this,tSql.toString());
		ArrayList tList = new ArrayList();
		Object[] tObj = new Object[2];
		tObj[0] = aBalanceYM;
		tObj[1] = aOrderDeptId;
		try{
			tList = this.executeQuery(new GSOrderDetailBean(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E00001,GSException.E00001_MSG);
		}
		return tList;
	}

	/**
	 * 根据供应商和结算截至日期查询未结算订单明细
	 * @param aOrderDeptId          订货单位编码
	 * @param aBalanceYM            结算截至日期
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryUnBalanceDetailProv(String aProvId,String aBalanceYM) throws GSException{
		StringBuffer tSql = new StringBuffer("select A.* from GS_ORDER_DETAIL A ,GS_ORDER B where A.GS_IS_PROV_BALANCEED='0'");
		//tSql.append(" and A.GS_ORDER_DETAIL_STATUS='12'");
		tSql.append(" and to_char(to_date(A.GS_SIGNIN_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <=?");
		tSql.append(" and A.GS_ORDER_TEMPID=B.GS_ORDER_TEMPID");
		tSql.append(" and a.GS_provider_ID=? and a.gs_balance_mode=? order by A.GS_PROVIDER_ID");
		GSLogWriter.info(this,tSql.toString());
		ArrayList tList = new ArrayList();

		Object[] tObj = new Object[3];
		tObj[0] = aBalanceYM;
		tObj[1] = aProvId;
		tObj[2] = GSBaseConstants.BALANCE_MODE1;
		try{
			tList = this.executeQuery(new GSOrderDetailBean(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E00001,GSException.E00001_MSG);
		}
		return tList;
	}
	/**
	 * 根据查询条件查询纳入结算的订单明细
	 * @param aVO               查询条件
	 * @param aOrg              订货单位
	 * @param pageNo            页号
	 * @param pageSize          页笔数
	 * @return
	 * @throws GSException
	 */
	public ArrayList querySignedDetail(GSUnBalanceDetailQryVO aVO,ArrayList aOrg,int pageNo,int pageSize) throws GSException{
		ArrayList tList = null;

		StringBuffer tSql = new StringBuffer();
		tSql.append(getSignedOrgDetailSql(aVO,aOrg));
		tSql.append(" order by P15,P19 asc,a.GS_LASTMODIFY_DATE,a.GS_DELIVER_GOODS_ID desc");
		GSLogWriter.info(this,tSql.toString());
		try{
			tList = this.executeQuery(new GSUnBalanceDetailQryResultVO(),tSql.toString(),null,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 根据查询条件查询纳入结算的订单明细笔数
	 * @param aVO           查询条件
	 * @param aOrg          订货单位
	 * @return
	 * @throws GSException
	 */
	public int querySignedDetailCount(GSUnBalanceDetailQryVO aVO,ArrayList aOrg) throws GSException{
		int tSize = 0;
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getSignedOrgDetailSql(aVO,aOrg));
		tSql.append(")");
		GSLogWriter.info(this,tSql.toString());
		try{
			tSize = this.queryRowNum(tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}
	/**
	 * 取得查询订货单位所对应的纳入结算的订单明细的SQL
	 * @param aVO
	 * @param aOrg
	 * @return
	 * @throws GSException
	 */
	private String getSignedOrgDetailSql(GSUnBalanceDetailQryVO aVO,ArrayList aOrg) throws GSException{
		if(aOrg == null){
			aOrg =new ArrayList();
			String[] tTmpOrg ={"NoOrg"};
			aOrg.add(tTmpOrg);
		}
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,b.GS_MANUFACTURE_UNITPRICE as P13,a.GS_ORDER_TEMPID as P14,");
		tSql.append("d.GS_PROVIDER_ID as P15,d.GS_IS_TRADEFLAT_PROVIDER as P16,a.GS_DELIVER_GOODS_ID as P17,");
		tSql.append("a.GS_SIGNIN_COUNT as P18,a.GS_SIGNIN_DATE as P19,b.GS_MANUFACTURER_NAME as P20,b.gs_manufacture_id as P21,");
		tSql.append("a.GS_LASTMODIFY_DATE,a.gs_balance_mode ");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e");
		tSql.append(" where a.GS_ORDER_DETAIL_STATUS='12' and e.GS_ORDER_TEMPID=a.GS_ORDER_TEMPID");
		tSql.append(" and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and a.GS_IS_BALANCEED = '1'");
		tSql.append(" and a.GS_PROVIDER_ID=d.GS_PROVIDER_ID ");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and a.GS_provider_ID='" + aVO.deptId + "'");
		tSql.append(" and (a.GS_DELIVER_GOODS_DATE IS NULL or (");
		if(aVO.deliverGoodsDateStr == null) {
			aVO.deliverGoodsDateStr = "00000000";
		}
		if(aVO.deliverGoodsDateEnd == null) {
			aVO.deliverGoodsDateEnd = "99999999";
		}
		if(aVO.deliverGoodsDateStr.trim().length() ==0) {
			aVO.deliverGoodsDateStr = "00000000";
		}
		if(aVO.deliverGoodsDateEnd.trim().length() ==0) {
			aVO.deliverGoodsDateEnd = "99999999";
		}

		tSql.append(" a.GS_DELIVER_GOODS_DATE  >='" + aVO.deliverGoodsDateStr.substring(0,4)+"-"+aVO.deliverGoodsDateStr.substring(4,6)+"-"+aVO.deliverGoodsDateStr.substring(6,8) + "'");
		tSql.append(" and  a.GS_DELIVER_GOODS_DATE  <='" + aVO.deliverGoodsDateEnd.substring(0,4)+"-"+aVO.deliverGoodsDateEnd.substring(4,6)+"-"+aVO.deliverGoodsDateEnd.substring(6,8) + "'");
		tSql.append(" ))");
		//tSql.append(" and to_char(to_date(A.GS_SIGNIN_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <='" + aVO.endBalDate+"'");
		//simonyi 2006-10-26 屏蔽上一句依赖签收时间的条件,在根据手选订单纳入结算时，判断签收时间没有意义
		tSql.append(" and A.GS_BALANCE_MONTH ='" + aVO.balanceYM + "'");
		if(aVO.orderDeptId!=null&&aVO.orderDeptId.trim().length()!=0){
			tSql.append(" and e.GS_workcorp_ID='" + aVO.orderDeptId + "'");
		}
		if(aVO.deliverGoodsId != null && aVO.deliverGoodsId.trim().length() != 0){
			tSql.append(" and a.GS_DELIVER_GOODS_ID='" + aVO.deliverGoodsId + "'");
		}
		if(aVO.providerShortName != null && aVO.providerShortName.trim().length() != 0){
			tSql.append(" and d.GS_PROVIDER_SHORTNAME='" + aVO.providerShortName + "'");
		}
		if(aVO.concentricityId != null && aVO.concentricityId.trim().length() != 0){
			tSql.append(" and B.GS_CONCENTRICITY_ID ='" + aVO.concentricityId + "'");
		}
		if(aVO.manufInfo != null && aVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (b.GS_MANUFACTURE_NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_TYPE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURER_NAME like '%" + aVO.manufInfo +"%')");
		}

		return tSql.toString();
	}
	/**
	 * 取得查询供应商所对应的纳入结算的订单明细的SQL
	 * @param aVO
	 * @return
	 * @throws GSException
	 */
	private String getSignedProviderDetailSql(GSUnBalanceDetailQryVO aVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,b.GS_MANUFACTURE_UNITPRICE as P13,a.GS_ORDER_TEMPID as P14,");
		tSql.append("c.GS_ORG_ID as P15,d.GS_IS_TRADEFLAT_PROVIDER as P16,a.GS_DELIVER_GOODS_ID as P17,");
		tSql.append("a.GS_SIGNIN_COUNT as P18,a.GS_SIGNIN_DATE as P19,b.GS_MANUFACTURER_NAME as P20,b.gs_manufacture_id as P21,");
		tSql.append("a.GS_LASTMODIFY_DATE ");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e");
		tSql.append(" where e.GS_ORDER_TEMPID=a.GS_ORDER_TEMPID");
		tSql.append(" and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and a.GS_PROVIDER_ID=d.GS_PROVIDER_ID and a.GS_PROVIDER_ID=b.GS_PROVIDER_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and a.GS_PROVIDER_ID='" + aVO.deptId + "'");
		tSql.append(" and (a.GS_DELIVER_GOODS_DATE IS NULL or (");
		if(aVO.deliverGoodsDateStr == null) {
			aVO.deliverGoodsDateStr = "00000000";
		}
		if(aVO.deliverGoodsDateEnd == null) {
			aVO.deliverGoodsDateEnd = "99999999";
		}
		if(aVO.deliverGoodsDateStr.trim().length() ==0) {
			aVO.deliverGoodsDateStr = "00000000";
		}
		if(aVO.deliverGoodsDateEnd.trim().length() ==0) {
			aVO.deliverGoodsDateEnd = "99999999";
		}

		tSql.append(" a.GS_DELIVER_GOODS_DATE  >='" + aVO.deliverGoodsDateStr.substring(0,4)+"-"+aVO.deliverGoodsDateStr.substring(4,6)+"-"+aVO.deliverGoodsDateStr.substring(6,8) + "'");
		tSql.append(" and  a.GS_DELIVER_GOODS_DATE  <='" + aVO.deliverGoodsDateEnd.substring(0,4)+"-"+aVO.deliverGoodsDateEnd.substring(4,6)+"-"+aVO.deliverGoodsDateEnd.substring(6,8) + "'");
		tSql.append(" ))");
		//tSql.append(" and to_char(to_date(A.GS_SIGNIN_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <='" + aVO.endBalDate+"'");
		//simonyi 2006-10-26 屏蔽上一句依赖签收时间的条件,在根据手选订单纳入结算时，判断签收时间没有意义
		tSql.append(" and A.GS_BALANCE_MONTH_PROVIDER ='" + aVO.balanceYM + "'");
		/*        if(!aVO.orderDeptId.equals("0000")){
            tSql.append(" and e.GS_WORKCORP_ID ='" + aVO.orderDeptId + "'");
        }else{
            if(aOrg != null && aOrg.size() > 0){
                tSql.append(" and e.GS_WORKCORP_ID in(");
                for(int i=0; i<aOrg.size();i++){
                    String tStr[] = (String[])aOrg.get(i);
                        if( i == aOrg.size()-1){
                            tSql.append("'"+tStr[0]+"')");
                        }else{
                            tSql.append("'"+tStr[0]+"',");
                        }
                }
            }
        }*/
		if(aVO.deliverGoodsId != null && aVO.deliverGoodsId.trim().length()!= 0){
			tSql.append(" and a.GS_DELIVER_GOODS_ID='" + aVO.deliverGoodsId + "'");
		}
		if(aVO.providerShortName != null && aVO.providerShortName.trim().length() != 0){
			tSql.append(" and d.GS_PROVIDER_SHORTNAME='" + aVO.providerShortName + "'");
		}
		if(aVO.concentricityId != null && aVO.concentricityId.trim().length() != 0){
			tSql.append(" and B.GS_CONCENTRICITY_ID ='" + aVO.concentricityId + "'");
		}
		if(aVO.manufInfo != null && aVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (b.GS_MANUFACTURE_NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_TYPE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURER_NAME like '%" + aVO.manufInfo +"%')");
		}

		return tSql.toString();
	}
	ArrayList tList = null;
	/**
	 * 查询结算相关的订单明细信息
	 * @param aDeptId           订货单位编号
	 * @param aDeptCategory     公司类型
	 * @param aEndBalDate       结算截至日期
	 * @param aBalYM            结算月份
	 * @param pageNo            页号
	 * @param pageSize          页笔数
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryDetailAssociatedBalanced(String aDeptId,String aDeptCategory,String aEndBalDate,String aBalYM,int pageNo,int pageSize) throws GSException{

		StringBuffer tSql = new StringBuffer();
		if(aDeptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
			tSql.append(getBalancedOrgDetailSql(aDeptId,aEndBalDate,aBalYM));
		}else{
			tSql.append(getBalancedProviderDetailSql(aDeptId,aEndBalDate,aBalYM));
		}
		tSql.append(" order by P15,P19 asc,a.GS_LASTMODIFY_DATE desc");
		GSLogWriter.info(this,tSql.toString());
		try{
			tList = this.executeQuery(new GSBalancedDetailQryResultVO(),tSql.toString(),null,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询纳入结算的明细
	 * @param aDeptId           订货单位编号
	 * @param aDeptCategory     公司类别
	 * @param aEndBalDate       结算截至日期
	 * @param aBalYM            结算月份
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryDetailAssociatedBalanced(String aDeptId,String aDeptCategory,String aEndBalDate,String aBalYM) throws GSException{

		StringBuffer tSql = new StringBuffer();
		if(aDeptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
			tSql.append(getBalancedOrgDetailSql(aDeptId,aEndBalDate,aBalYM));
		}else{
			tSql.append(getBalancedProviderDetailSql(aDeptId,aEndBalDate,aBalYM));
		}
		tSql.append(" order by P15,P19 asc");
		GSLogWriter.info(this,tSql.toString());
		try{
			tList = this.executeQuery(new GSBalancedDetailQryResultVO(),tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询纳入结算的明细（供应商）
	 * @param aDeptId           供应商编号
	 * @param aEndBalDate       结算截至日期
	 * @param aBalYM            结算月份
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryDetailAssociatedBalanced(String aDeptId,String aEndBalDate,String aBalYM) throws GSException{

		StringBuffer tSql = new StringBuffer();
		tSql.append(getBalancedProviderDetailSql(aDeptId,aEndBalDate,aBalYM));
		try{
			tList = this.executeQuery(new GSBalancedDetailProvResultVO(),tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询纳入结算的订单明细笔数
	 * @param aDeptId           单位编号
	 * @param aDeptCategory     单位类别
	 * @param aEndBalDate       截至结算日期
	 * @param aBalYM            结算月份
	 * @return
	 * @throws GSException
	 */
	public int queryDetailAssociatedBalancedCount(String aDeptId,String aDeptCategory,String aEndBalDate,String aBalYM) throws GSException{
		int tSize = 0;
		StringBuffer tSql = new StringBuffer("select count(*) from (");
		if(aDeptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
			tSql.append(getBalancedOrgDetailSql(aDeptId,aEndBalDate,aBalYM));
		}else{
			tSql.append(getBalancedProviderDetailSql(aDeptId,aEndBalDate,aBalYM));
		}
		tSql.append(")");
		GSLogWriter.info(this,tSql.toString());
		try{
			tSize = this.queryRowNum(tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}
	/**
	 * 取得查询订货单位所对应纳入结算的订单明细SQL
	 * @param aOrgId
	 * @param aEndBalDate
	 * @param aBalYM
	 * @return
	 * @throws GSException
	 */
	private String getBalancedOrgDetailSql(String aOrgId,String aEndBalDate,String aBalYM) throws GSException{
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,b.GS_MANUFACTURE_UNITPRICE as P13,a.GS_ORDER_TEMPID as P14,");
		tSql.append("d.GS_org_ID as P15,d.GS_IS_TRADEFLAT_PROVIDER as P16,a.GS_DELIVER_GOODS_ID as P17,");
		tSql.append("a.GS_SIGNIN_COUNT as P18,a.GS_SIGNIN_DATE as P19,b.GS_MANUFACTURER_NAME as P20,a.GS_MANUFACTURE_ID as P21,a.GS_LASTMODIFY_DATE");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e");
		tSql.append(" where a.GS_ORDER_DETAIL_STATUS='14' and e.GS_ORDER_TEMPID=a.GS_ORDER_TEMPID");
		tSql.append(" and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and a.GS_IS_BALANCEED = '1'");
		tSql.append(" and a.GS_PROVIDER_ID=d.GS_PROVIDER_ID and a.GS_PROVIDER_ID=b.GS_PROVIDER_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and e.GS_WORKCORP_ID='" + aOrgId + "'");
		tSql.append(" and a.GS_SIGNIN_DATE <='" + aEndBalDate.substring(0,4)+"-"+aEndBalDate.substring(4,6)+"-"+aEndBalDate.substring(6,8)+"'");
		tSql.append(" and a.GS_BALANCE_MONTH ='" + aBalYM + "'");
		return tSql.toString();
	}
	/**
	 * 查询供应商所对应的已纳入结算的订单明细
	 * @param aDeptId
	 * @param aEndBalDate
	 * @param aBalYM
	 * @return
	 * @throws GSException
	 */
	private String getBalancedProviderDetailSql(String aDeptId,String aEndBalDate,String aBalYM) throws GSException{
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,b.GS_MANUFACTURE_UNITPRICE as P13,a.GS_ORDER_TEMPID as P14,");
		tSql.append("a.GS_PROVIDER_ID as P15,d.GS_IS_TRADEFLAT_PROVIDER as P16,a.GS_DELIVER_GOODS_ID as P17,");
		tSql.append("a.GS_SIGNIN_COUNT as P18,a.GS_SIGNIN_DATE as P19,b.GS_MANUFACTURER_NAME as P20,a.GS_MANUFACTURE_ID as P21,a.GS_LASTMODIFY_DATE,a.gs_balance_month,a.gs_balance_month_provider ");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e");
		tSql.append(" where e.GS_ORDER_TEMPID=a.GS_ORDER_TEMPID");
		tSql.append(" and (a.GS_ORDER_DETAIL_STATUS='12' or a.GS_ORDER_DETAIL_STATUS='14')");
		tSql.append(" and a.GS_CONCENTRICITY_ID= b.GS_CONCENTRICITY_ID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and a.GS_PROVIDER_ID=d.GS_PROVIDER_ID and a.GS_PROVIDER_ID=b.GS_PROVIDER_ID");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and a.GS_PROVIDER_ID='" + aDeptId + "'");
		tSql.append(" and a.GS_SIGNIN_DATE  <='" + aEndBalDate.substring(0,4)+"-"+aEndBalDate.substring(4,6)+"-"+aEndBalDate.substring(6,8)+"'");
		tSql.append(" and a.GS_BALANCE_MONTH_PROVIDER ='" + aBalYM + "'");
		return tSql.toString();
	}
	/**
	 * 查询已纳入结算订单明细
	 * @param aOrderDeptId      订货单位编码
	 * @param aBalanceYM        结算月份
	 * @param aBalEndDate       结算结束日期
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryBalancedDetail(String aOrderDeptId,String aBalanceYM,String aBalEndDate) throws GSException{
		StringBuffer tSql = new StringBuffer("select A.* from GS_ORDER_DETAIL A ,GS_ORDER B where A.GS_IS_BALANCEED='1'");
		tSql.append(" and A.GS_ORDER_DETAIL_STATUS='12'");
		tSql.append(" and A.GS_BALANCE_MONTH ='"+aBalanceYM+"'");
		tSql.append(" and A.GS_ORDER_TEMPID=B.GS_ORDER_TEMPID");
		tSql.append(" and B.GS_WORKCORP_ID='"+aOrderDeptId+"' order by A.GS_PROVIDER_ID");
		ArrayList tList = new ArrayList();

		//这里的参数虽然传递正确，但是很奇怪地查询不出结果
		/*
        Object[] tObj = new Object[3];
        tObj[0] = aBalEndDate;
        tObj[1] = aBalanceYM;
        tObj[2] = aOrderDeptId;
		 */
		Object[] tObj = null;
		try{
			tList = this.executeQuery(new GSOrderDetailBean(),tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E00001,GSException.E00001_MSG);
		}
		return tList;
	}
	/**
	 * 修改订单明细结算信息
	 * @param aConn                 DB连接
	 * @param aOrderDetailBean      待修改数据
	 * @return
	 * @throws GSException
	 */
	public boolean updateDetailBalanced(Connection aConn, GSOrderDetailBean aOrderDetailBean) throws GSException{
		boolean tFlag = false;
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_IS_BALANCEED='1'");
		tSql.append(",GS_BALANCE_MONTH='" + aOrderDetailBean.getGs_balance_month() + "'");
		tSql.append(",GS_BALANCE_MONTH_PROVIDER='" + aOrderDetailBean.getGs_balance_month_provider() + "'");
		if(aOrderDetailBean.getGs_lastmodifer_id() != null){
			tSql.append(",GS_LASTMODIFER_ID='" + aOrderDetailBean.getGs_lastmodifer_id() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_date() != null){
			tSql.append(",GS_LASTMODIFY_DATE='" + aOrderDetailBean.getGs_lastmodify_date() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_contents() != null){
			tSql.append(",GS_LASTMODIFY_CONTENTS='" + aOrderDetailBean.getGs_lastmodify_contents() + "'");
		}
		tSql.append(" where GS_ORDER_DETAIL_ID='" + aOrderDetailBean.getGs_order_detail_id()+"'");
		GSLogWriter.debug(this,"Sql=" + tSql.toString());
		Object tObj[] = {};
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19994,GSException.E19994_MSG);
		}
		return tFlag;
	}
	/**
	 * 修改订单明细结算信息
	 * @param aConn                 DB连接
	 * @param aOrderDetailBean      待修改数据
	 * @return
	 * @throws GSException
	 */
	public boolean updateDetailBalancedProv(Connection aConn, GSOrderDetailBean aOrderDetailBean) throws GSException{
		boolean tFlag = false;
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_IS_PROV_BALANCEED='1'");
		tSql.append(",GS_BALANCE_MONTH='" + aOrderDetailBean.getGs_balance_month() + "'");
		tSql.append(",GS_BALANCE_MONTH_PROVIDER='" + aOrderDetailBean.getGs_balance_month_provider() + "'");
		if(aOrderDetailBean.getGs_lastmodifer_id() != null){
			tSql.append(",GS_LASTMODIFER_ID='" + aOrderDetailBean.getGs_lastmodifer_id() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_date() != null){
			tSql.append(",GS_LASTMODIFY_DATE='" + aOrderDetailBean.getGs_lastmodify_date() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_contents() != null){
			tSql.append(",GS_LASTMODIFY_CONTENTS='" + aOrderDetailBean.getGs_lastmodify_contents() + "'");
		}
		tSql.append(" where GS_ORDER_DETAIL_ID='" + aOrderDetailBean.getGs_order_detail_id()+"'");
		GSLogWriter.debug(this,"Sql=" + tSql.toString());
		Object tObj[] = {};
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19994,GSException.E19994_MSG);
		}
		return tFlag;
	}

	/**
	 * 未结算信息导出时查询已被纳入结算的订单明细
	 * @param aVO       查询条件
	 * @param aOrg      订货单位
	 * @return
	 * @throws GSException
	 */
	public ArrayList querySignedDetail(GSUnBalanceDetailQryVO aVO,ArrayList aOrg) throws GSException{
		ArrayList tList = null;

		StringBuffer tSql = new StringBuffer();
		if(aVO.deptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
			tSql.append(getSignedOrgDetailSql(aVO,aOrg));
		}else{
			tSql.append(getSignedProviderDetailSql(aVO));
		}
		tSql.append(" order by P15,P17 asc");
		GSLogWriter.info(this,tSql.toString());
		try{
			//为了在导出文件时调用同一个写文件方法，此处查询结果也放入已结算明细结果GSUnBalanceDetailQryResultVO对象
			tList = this.executeQuery(new GSBalancedDetailQryResultVO(),tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 修改未最终完成结算明细
	 * @param aOrderDetailBean
	 * @param aConn
	 * @param aOldStatus
	 * @return
	 * @throws GSException
	 */
	public boolean updateUnBalanceDetail(GSOrderDetailBean aOrderDetailBean,Connection aConn,String aOldStatus) throws GSException{
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_ORDER_DETAIL_STATUS='" + aOrderDetailBean.getGs_order_detail_status() + "'");
		if(aOrderDetailBean.getGs_lastmodifer_id() != null){
			tSql.append(",GS_LASTMODIFER_ID='" + aOrderDetailBean.getGs_lastmodifer_id() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_date() != null){
			tSql.append(",GS_LASTMODIFY_DATE='" + aOrderDetailBean.getGs_lastmodify_date() + "'");
		}
		if(aOrderDetailBean.getGs_lastmodify_contents() != null){
			tSql.append(",GS_LASTMODIFY_CONTENTS='" + aOrderDetailBean.getGs_lastmodify_contents() + "'");
		}

		if(aOrderDetailBean.getGs_deliver_goods_id() != null){
			tSql.append(",GS_DELIVER_GOODS_ID='" + aOrderDetailBean.getGs_deliver_goods_id() + "'");
		}
		if(aOrderDetailBean.getGs_deliveryman() != null){
			tSql.append(",GS_DELIVERYMAN='" + aOrderDetailBean.getGs_deliveryman() + "'");
		}
		if(aOrderDetailBean.getGs_deliver_goods_phone() != null){
			tSql.append(",GS_DELIVER_GOODS_PHONE='" + aOrderDetailBean.getGs_deliver_goods_phone() + "'");
		}
		if(aOrderDetailBean.getGs_signin_count() != 0){
			tSql.append(",GS_SIGNIN_COUNT=" + aOrderDetailBean.getGs_signin_count());
		}
		if(aOrderDetailBean.getGs_signin_date() != null){
			tSql.append(",GS_SIGNIN_DATE='" + aOrderDetailBean.getGs_signin_date()+"'");
		}
		if(aOrderDetailBean.getGs_signin_time() != null){
			tSql.append(",GS_SIGNIN_TIME='" + aOrderDetailBean.getGs_signin_time() + "'");
		}
		if(aOrderDetailBean.getGs_signin_person() != null){
			tSql.append(",GS_SIGNIN_PERSON='" + aOrderDetailBean.getGs_signin_person() +"'");
		}
		if(aOrderDetailBean.getGs_goods_unitprice() != 0){
			tSql.append(",GS_GOODS_UNITPRICE=" + aOrderDetailBean.getGs_goods_unitprice());
		}
		//        if(aOrderDetailBean.getGs_is_balanced() != null){
		//            tSql.append(",GS_IS_BALANCEED='" + aOrderDetailBean.getGs_is_balanced() + "'");
		//        }
		tSql.append(" where GS_ORDER_DETAIL_ID='" + aOrderDetailBean.getGs_order_detail_id() + "' ");
		tSql.append("and GS_ORDER_DETAIL_STATUS = '" + aOldStatus + "'");
		GSLogWriter.debug(this,"Sql=" + tSql.toString());
		Object tObj[] = {};
		boolean tFlag = false;
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19994,GSException.E19994_MSG);
		}
		return tFlag;
	}
	/**
	 * 查询历史订单明细
	 * @param aGSOrderVO    查询参数
	 * @param aOrg          可查询订货单位
	 * @param pageNo        页号
	 * @param pageSize      每页笔数
	 * @return
	 * @throws GSException
	 */
	public  ArrayList queryHistoryOrderDetail(GSOrderVO aGSOrderVO,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer();
		tSql.append(getOrderDtlSqlForStatusTrace(aGSOrderVO));
		tSql.append(" order by det.GS_LASTMODIFY_DATE desc");
		GSLogWriter.debug(this,tSql.toString());
		ArrayList tList = new ArrayList();
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderAnaDetailBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询历史订单明细笔数
	 * @param aGSOrderVO    查询参数
	 * @param aOrg          可查询订货单位
	 * @return
	 * @throws GSException
	 */
	public int queryHistoryOrderDetailCount(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from (");
		tSql.append(getOrderDtlSqlForStatusTrace(aGSOrderVO));
		tSql.append(")");
		int tSize = 0;
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tSize = this.queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;
	}
	/**
	 * 修改订单明细
	 * @param aBean             待修改数据
	 * @param aConn             DB连接
	 * @return
	 * @throws GSException
	 */
	public boolean updateDetailAsOrdering(GSOrderAnaDetailAndCategoryBean aBean,Connection aConn) throws GSException{
		boolean tFlag = false;
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_PROVIDER_ID=?,");
		tSql.append("GS_MANUFACTURE_ID=?,GS_GOODS_UNITPRICE=?,");
		tSql.append("GS_ORDER_COUNT=?,GS_LASTMODIFER_ID=?,");
		tSql.append("GS_LASTMODIFY_CONTENTS=?,GS_LASTMODIFY_DATE=?,GS_ORDER_DETAIL_STATUS=?,");
		tSql.append("GS_SUBMITER_ID2=?,GS_SUBMIT_DATE2=?, ");
		tSql.append("GS_DELIVER_GOODS_DATE = ?, GS_DELIVER_GOODS_TIME = ? ,");
		tSql.append("GS_AUTHORIZER_ID = ?, GS_AUTHORIZE_DATE = to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') ");
		tSql.append("where GS_ORDER_DETAIL_ID=?");
		Object[] tObj = new Object[14];
		tObj[0] = aBean.getGs_provider_id();
		tObj[1] = aBean.getGs_manufacture_id();
		tObj[2] = String.valueOf(aBean.getGs_goods_unitprice());
		tObj[3] = String.valueOf(aBean.getGs_order_count());
		tObj[4] = aBean.getGs_lastmodifer_id();
		tObj[5] = aBean.getGs_lastmodify_contents();
		tObj[6] = aBean.getGs_lastmodify_date();
		tObj[7] = aBean.getGs_order_detail_status();
		tObj[8] = aBean.getGs_submiter_id2();
		tObj[9] = aBean.getGs_submit_date2();
		tObj[10] = aBean.getGs_deliver_goods_date();
		tObj[11] = aBean.getGs_deliver_goods_time();
		tObj[12] = aBean.getGs_authorizer_id();
		tObj[13] = aBean.getGs_order_detail_id();
		try{
			tFlag = this.executeUpdate(aConn,tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19995,GSException.E19995_MSG);
			//            throw new GSException(e.toString());
		}
		return tFlag;
	}
	/**
	 * 查询可新增到结算信息中的订单
	 * @param aVO
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryAddableSignedDetail(GSUnBalanceDetailQryVO aVO,int pageNo, int pageSize) throws GSException{
		ArrayList tList = new ArrayList();
		StringBuffer tSql = new StringBuffer(getAddableSignedOrgDetailSql(aVO));
		tSql.append(" order by P15,P19 desc");
		GSLogWriter.info(this,tSql.toString());
		try{
			tList = this.executeQuery(new GSAddUnBalanceDetailQryResultVO(),tSql.toString(),null,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}
	/**
	 * 查询可新增到结算信息中的订单笔数
	 * @param aVO
	 * @return
	 * @throws GSException
	 */
	public int queryAddableSignedDetailCount(GSUnBalanceDetailQryVO aVO) throws GSException{
		int tSize = 0;
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getAddableSignedOrgDetailSql(aVO));
		tSql.append(")");
		try{
			tSize = this.queryRowNum(tSql.toString(),null);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tSize;

	}
	/**
	 * 取得可新增到结算信息中的查询订单SQL
	 * @param aVO
	 * @return
	 * @throws GSException
	 */
	private String getAddableSignedOrgDetailSql(GSUnBalanceDetailQryVO aVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,b.GS_MANUFACTURE_NAME as P3,");
		tSql.append("b.GS_IS_TRADEFLAT_MANUFACTURE as P4,b.GS_MANUFACTURE_SPEC as P5,b.GS_MANUFACTURE_TYPE as P6,b.GS_MANUFACTURE_BRAND as P7,");
		tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,d.GS_PROVIDER_SHORTNAME as P10,c.GS_ORG_NAME as P11,");
		tSql.append("a.GS_GOODS_UNITPRICE as P12,a.GS_ORDER_TEMPID as P14,");
		tSql.append("d.GS_PROVIDER_ID as P15,d.GS_IS_TRADEFLAT_PROVIDER as P16,e.GS_ORDER_CREATE_DATE as P17,");
		tSql.append("a.GS_DELIVER_GOODS_DATE as P18,a.GS_DELIVER_GOODS_TIME as P19,a.GS_SIGNIN_COUNT as P20,");
		tSql.append("a.GS_LASTMODIFY_DATE,a.gs_balance_mode ");
		tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d,GS_ORDER e,");
		tSql.append(" GS_ORDER_DEPT_INFO f,GS_MANUFACTURE_CATEGORY g");
		tSql.append(" where a.GS_ORDER_DETAIL_STATUS='12' and e.GS_ORDER_TEMPID=a.GS_ORDER_TEMPID");
		tSql.append(" and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID");
		tSql.append(" and (a.GS_IS_BALANCEED = '0' or a.GS_IS_PROV_BALANCEED = '0') ");
		tSql.append(" and a.GS_PROVIDER_ID=d.GS_PROVIDER_ID ");
		tSql.append(" and e.GS_WORKCORP_ID=c.GS_ORG_ID and a.GS_provider_ID='" + aVO.proverid + "'");
		if(aVO.orderCreateDateStr != null) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE >='" + aVO.orderCreateDateStr.substring(0,4)+"-"+aVO.orderCreateDateStr.substring(4,6)+"-"+aVO.orderCreateDateStr.substring(6,8) + "'");
		}
		if(aVO.orderCreateDateEnd != null) {
			tSql.append(" and e.GS_ORDER_CREATE_DATE <='" + aVO.orderCreateDateEnd.substring(0,4)+"-"+aVO.orderCreateDateEnd.substring(4,6)+"-"+aVO.orderCreateDateEnd.substring(6,8) + " 23:59:59'");
		}
		if(aVO.endBalDate != null) {
			tSql.append(" and A.GS_SIGNIN_DATE <='" + aVO.endBalDate.substring(0,4)+"-"+aVO.endBalDate.substring(4,6)+"-"+aVO.endBalDate.substring(6,8)+"'");
		}

		tSql.append(" and a.GS_ORDER_DETAIL_STATUS='12'");
		tSql.append(" and b.GS_MANUFACTURE_CATEGORY_ID=g.GS_MANUFACTURE_CATEGORY_ID");
		if(aVO.orderDetailId != null && !aVO.orderDetailId.equals("")){
			tSql.append(" and a.GS_ORDER_DETAIL_ID='" + aVO.orderDetailId + "'");
		}
		if(aVO.providerShortName != null && !aVO.providerShortName.equals("")){
			tSql.append(" and d.GS_PROVIDER_SHORTNAME='" + aVO.providerShortName + "'");
		}
		if(aVO.concentricityId != null && !aVO.concentricityId.trim().equals("")){
			tSql.append(" and B.GS_CONCENTRICITY_ID ='" + aVO.concentricityId + "'");
		}
		if(aVO.manufInfo != null && aVO.manufInfo.trim().length()!= 0){
			tSql.append(" and (b.GS_MANUFACTURE_NAME like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_TYPE like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_SPEC like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURE_BRAND like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_APPENDER_PROPERTY like '%" + aVO.manufInfo + "%'");
			tSql.append(" or b.GS_MANUFACTURER_NAME like '%" + aVO.manufInfo +"%')");
		}
		if(aVO.manufType1!= null && aVO.manufType1.trim().length() != 0){
			if(aVO.manufType1.equals("0")){
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID like '%'");
			}else if(aVO.manufType2.equals("0")){
				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID1 ='" + aVO.manufType1 + "'");
				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType1 + "')");
			}else if(aVO.manufType3.equals("0")){
				tSql.append(" and (g.GS_MANUFACTURE_CATEGORY_ID2 ='" + aVO.manufType2 + "'");
				tSql.append(" or g.GS_MANUFACTURE_CATEGORY_ID='" + aVO.manufType2 + "')");
			}else{
				tSql.append(" and g.GS_MANUFACTURE_CATEGORY_ID ='" + aVO.manufType3 + "'");
			}
		}
		if(aVO.deliverGoodsId != null && aVO.deliverGoodsId.trim().length() != 0){
			tSql.append(" and a.GS_DELIVER_GOODS_ID='" + aVO.deliverGoodsId + "'");
		}
		if(aVO.orderType.equals("0000")){
			tSql.append(" and (e.GS_ORDER_CATEGORY = '1' or e.GS_ORDER_CATEGORY='0')");
		}else {
			tSql.append(" and e.GS_ORDER_CATEGORY='" + aVO.orderType + "'");
		}
		//只显示结算模式为买断的订单
		tSql.append(" and a.gs_balance_mode='0' ");
		return tSql.toString();
	}

	public String getWorkCorp(String ordDtlCode) throws GSException {
		String rt = "";

		GSOrderBean tGSOrderBean = new GSOrderBean();
		String sql = "select t.* from gs_order t, gs_order_detail s "  +
		"where s.gs_order_detail_id =? and t.gs_order_tempid = s.gs_order_tempid ";

		ArrayList tList = null;

		Object[] tObj = { ordDtlCode };
		try {
			tList = this.executeQuery(new GSOrderBean(), sql, tObj);
			if (tList.size() == 1) {
				tGSOrderBean = (GSOrderBean) tList.get(0);
			} else {
				// throw new
				// GSException(GSException.BME20041,GSException.BME20041_MSG);
			}
		} catch (Exception e) {
			GSLogWriter.error(this, e.toString());
			throw new GSException(GSException.E10040, GSException.E10040_MSG);
		}
		String orgid = "";
		orgid = tGSOrderBean.getGs_workcorp_id();
		if (orgid == null ) {
			GSLogWriter.error("WorkCorp ID is null");
			return rt;
		}
		if (orgid.length() != 4 ) {
			GSLogWriter.error("WorkCorp ID length isn't 4");
			return rt;
		}
		GSOrganizationDAO orgdao = new GSOrganizationDAO();
		if (orgid.substring(2,4).equals("00")){
			rt = orgdao.queryOrgName(orgid);
		}
		else{
			rt = orgdao.getParentOrg(orgid).getGs_org_name();
		}
		return rt;
	}

	/**
	 * 修改订单明细状态为交货确认
	 * @param orderDetailId 订单明细ID
	 * @param signQty 签收数量
	 * @param signDate 签收日期
	 * @author wp
	 * 
	 */
	public boolean updateOrderDetailDeliverGoods(String orderDetailId, double signQty, String signDate, double signPrice) throws GSException {
		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL set GS_ORDER_DETAIL_STATUS = '");
		tSql.append(GSBaseConstants.ORDER_DELIVERY_CONFIRM).append("'");
		tSql.append(", GS_SIGNIN_DATE='").append(signDate).append("'");
		tSql.append(", GS_SIGNIN_COUNT=").append(signQty);
		tSql.append(", GS_GOODS_UNITPRICE=").append(signPrice);
		tSql.append(", GS_LASTMODIFY_DATE = to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss')");
		tSql.append(" where GS_ORDER_DETAIL_ID = '").append(orderDetailId).append("'");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			this.executeUpdate(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E10065,GSException.E10065_MSG);
		}
		return true;
	}

	/**
	 * 根据订单明细ID更改配送信息
	 * @author wp
	 */
	public boolean updateOrderDetainDeliverInfo(String[] aOrderDetailIds) throws GSException {

		if(aOrderDetailIds == null || aOrderDetailIds.length == 0) {
			return false;
		}

		StringBuffer tSql = new StringBuffer("update GS_ORDER_DETAIL SET GS_DELIVER_GOODS_COUNTS = GS_ORDER_COUNT");
		tSql.append(" ,GS_DELIVER_GOODS_CONFIRM_DATE = to_char(sysdate, 'yyyy-mm-dd'),");
		tSql.append(" GS_DELIVER_GOODS_ID = 'N/A',");
		tSql.append(" GS_ORDER_DETAIL_STATUS='").append(GSBaseConstants.ORDER_ORDER_CONFIRM).append("',");
		tSql.append(" GS_LASTMODIFY_DATE= to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss')");
		tSql.append(" where GS_ORDER_DETAIL_STATUS in ('").append(GSBaseConstants.ORDER_ORDERING).append("',").append("'").append(GSBaseConstants.ORDER_SECONDAUDIT_PASS).append("')");

		tSql.append(" and GS_ORDER_DETAIL_ID = ");

		try {
			for(int i=0; i<aOrderDetailIds.length; i++) {
				Object[] tObj = {};
				this.executeUpdate(tSql.toString()+"'"+aOrderDetailIds[i]+"'", tObj);
			}
		} catch(Exception e) {
			GSLogWriter.error(this, e.getLocalizedMessage());
			throw new GSException(GSException.E10065,GSException.E10065_MSG);
		}

		return true;

	}

	static final String NewBatchsql = "insert into (select GS_ORDER_TEMPID,"+
	"GS_ORDER_DETAIL_ID,"+
	"GS_MANUFACTURE_ID,"+
	"GS_CONCENTRICITY_ID,"+
	"GS_ORDER_COUNT,"+
	"GS_DELIVER_GOODS_DATE,"+
	"GS_DELIVER_GOODS_TIME,"+
	"GS_ORDER_DETAIL_STATUS,"+
	"GS_PROVIDER_ID,"+
	"GS_LASTMODIFER_ID,"+
	"GS_LASTMODIFY_CONTENTS,"+
	"GS_LASTMODIFY_DATE,"+
	"GS_GOODS_UNITPRICE,"+
	"GS_IS_BALANCEED,"+
	"GS_IS_PROV_BALANCEED,"+
	"GS_BALANCE_CATEGORY_NO,gs_balance_mode from gs_order_detail)"+
	"select GS_ORDER_TEMPID,"+
	"?,"+                          //new GS_ORDER_DETAIL_ID
	"GS_MANUFACTURE_ID,"+
	"GS_CONCENTRICITY_ID,"+
	"?,"+                          //GS_ORDER_COUNT
	"?,"+                          //GS_DELIVER_GOODS_DATE
	"GS_DELIVER_GOODS_TIME,"+
	"'3',"+                        //GS_ORDER_DETAIL_STATUS:复审通过(6)
	"GS_PROVIDER_ID,"+
	"GS_LASTMODIFER_ID,"+
	"GS_LASTMODIFY_CONTENTS,"+
	"GS_LASTMODIFY_DATE,"+
	"GS_GOODS_UNITPRICE,"+
	"GS_IS_BALANCEED,"+
	"GS_IS_PROV_BALANCEED,"+
	"GS_BALANCE_CATEGORY_NO,gs_balance_mode  from gs_order_detail where GS_ORDER_DETAIL_ID =?"; //GS_ORDER_DETAIL_ID

	/**
	 * 在原订单明细的基础上创建分批订单明细
	 * @param ArrayList tList 需要创建的分批订单明细数据
	 * @return
	 * @throws GSException
	 * @throws GSException
	 */
	public void creatNewBatchOrderDetail(ArrayList aList) throws GSException{


		Connection conn = getConnetion();
		PreparedStatement pstmt = null;
		try{
			conn.setAutoCommit(false);
			pstmt = conn.prepareStatement(NewBatchsql);

			for(int i=0;i<aList.size();i++){
				GSOrderDetailModifyVO tGSOrderDetailModifyVO = (GSOrderDetailModifyVO)aList.get(i);
				//创建新的批次订单明细号
				//取得该订单的最后批次的明细号
				String tNewOrderDetailId =tGSOrderDetailModifyVO.orderDetailId;

				int tPos = tNewOrderDetailId.indexOf("F_");
				if(tPos != -1){
					tNewOrderDetailId =  tNewOrderDetailId.substring(0,tPos);
				}
				pstmt.setString(1,tGSOrderDetailModifyVO.orderDetailId);
				pstmt.setDouble(2,tGSOrderDetailModifyVO.orderCount);
				pstmt.setString(3,tGSOrderDetailModifyVO.deliverGoodsDate);
				pstmt.setString(4,tNewOrderDetailId);
				pstmt.addBatch();

			}
			pstmt.executeBatch();
			conn.commit();
		}catch(Exception e){
			try{
				conn.rollback();
			}catch(SQLException sqle){}
			throw new GSException (GSException.E20051,GSException.E20051_MSG);
		}finally{
			try {
				conn.setAutoCommit(true);
			}
			catch (SQLException e) {}
			close(pstmt);
			close(conn);
		}
	}

	static final String GetRelationBatchsql =  "select * from gs_order_detail where gs_order_detail_id like ? order by gs_order_detail_id desc";

	/**
	 * 根据当前批次订单明细号查询数据库中相关的所有批次订单明细
	 * @throws GSException
	 */
	public ArrayList getRelationBatchOrder(String aOrderDetailId) throws GSException {
		ArrayList tList =new ArrayList();
		String tNewOrderDetailId = aOrderDetailId;

		int tPos = aOrderDetailId.indexOf("F_");
		if(tPos!= -1) {
			tNewOrderDetailId=aOrderDetailId.substring(0,tPos);
		}

		Object[] tObj = {tNewOrderDetailId+"%"};
		try{
			tList = executeQuery(new GSOrderDetailBean(),GetRelationBatchsql,tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}

		return tList;
	}

	/**
	 * 运营公司级申购综合查询订单
	 * @param aGSOrderVO        传入的查询参数VO对象
	 * @param aOrg              可查询订货单位ArrayList对象
	 * @param pageNo            页号
	 * @param pageSize          页大小
	 * @return
	 * @throws GSException
	 */
	public ArrayList queryOrderDetailByOpt_r(GSOrderVO aGSOrderVO,int pageNo,int pageSize) throws GSException{
		StringBuffer tSql = new StringBuffer(getOrderDetailByOptSql_r(aGSOrderVO));
		tSql.append(" order by det.GS_DELIVER_GOODS_DATE desc,det.GS_DELIVER_GOODS_TIME desc");
		ArrayList tList = new ArrayList();
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		try{
			tList = this.executeQuery(new GSOrderAnaDetailBean(),tSql.toString(),tObj,pageNo,pageSize);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tList;
	}

	/**
	 * 运营公司级申购综合查询订单笔数
	 * @param aGSOrderVO    查询参数封装VO
	 * @param aOrg          可查询订货单位对象
	 * @return
	 * @throws GSException
	 */
	public int queryOrderDetailCountByOpt_r(GSOrderVO aGSOrderVO) throws GSException{
		StringBuffer tSql = new StringBuffer("select count(*) from(");
		tSql.append(getOrderDetailByOptSql_r(aGSOrderVO));
		tSql.append(")");
		GSLogWriter.debug(this,tSql.toString());
		Object[] tObj = {};
		int size = 0;
		try{
			size = this.queryRowNum(tSql.toString(),tObj);
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return size;
	}
	/**
	 * 向交易平台发送失败
	 * */
	public boolean updateORDERRETURNSIGN(String orderId,String rSign,String msg) throws GSException{
		String sql="update gs_order_detail set GS_ORDERRETURN_SIGN=?,GS_ORDERRETURN_CONTENT=? where gs_order_detail_id=?";
		Object[] obj={rSign,msg,orderId};
		boolean bl;
		try {
			bl = this.executeUpdate(sql, obj);
		} catch (Exception e) {
			GSLogWriter.error(e.getMessage());
			throw new GSException(e.getMessage());
		}
		return bl;
	}

	public ArrayList getOrderDetailListPage(GSOrderDetailQueryBean bean) throws Exception {
		String sql = getOrderDetailListSql(bean);
		Object[] tobj = {};
		ArrayList tList = this.executeQuery(new GSOrderDetailQueryBean(), sql, tobj,bean.getCurrentPage(),bean.getPageSize());
		return tList;
	}

	private String getOrderDetailListSql(GSOrderDetailQueryBean bean) {
		StringBuffer result = new StringBuffer();
		result.append("select a.GS_PROVIDER_ID,a.GS_ORDER_DETAIL_STATUS,a.GS_DELIVER_GOODS_COUNTS,a.GS_ORDER_TEMPID,a.GS_GOODS_UNITPRICE,c.GS_ORDER_CREATE_DATE,b.ID,b.CONCENTRICITY_CODE,b.NAME,b.MODEL,b.SPEC,b.DRAWING_PIECE_CODE,a.GS_ORDER_DETAIL_ID,a.GS_BALANCE_MODE")
		.append(" from GS_ORDER_DETAIL a,T_PRODUCT b,GS_ORDER c")
		.append(" where a.GS_CONCENTRICITY_ID = b.CONCENTRICITY_CODE and a.GS_MANUFACTURE_ID = b.APEP_CODE and a.GS_ORDER_TEMPID = c.GS_ORDER_TEMPID");
		if(bean.getDrawingPieceCode()!=null && !bean.getDrawingPieceCode().equals(""))
			result.append(" and b.DRAWING_PIECE_CODE = '" + bean.getDrawingPieceCode()+"'");
		if(bean.getGsOrderDetailStatus() != null && !bean.getGsOrderDetailStatus().equals(""))
			result.append(" and a.GS_ORDER_DETAIL_STATUS = '"+bean.getGsOrderDetailStatus()+"'");
		if(bean.getProviderCode() !=null && !bean.getProviderCode().equals(""))
			result.append(" and a.GS_PROVIDER_ID = '"+bean.getProviderCode()+"'");
		if(bean.getGsOrderTempId() != null && !bean.getGsOrderTempId().equals(""))
			result.append(" and a.GS_ORDER_TEMPID = '"+bean.getGsOrderTempId()+"'");
		if(bean.getWarehouseCode() != null && !bean.getWarehouseCode().equals(""))
			result.append(" and c.GS_WORKCORP_ID = '"+bean.getWarehouseCode()+"'");
		if(bean.getProductCode() !=null && !bean.getProductCode().equals(""))
			result.append(" and b.CONCENTRICITY_CODE = '"+bean.getProductCode()+"' ");
		if(bean.getGsOrderCreateDateStart() !=null && !bean.getGsOrderCreateDateStart().equals(""))
			result.append(" and c.GS_ORDER_CREATE_DATE >= '"+bean.getGsOrderCreateDateStart()+" 00:00:00'");
		if(bean.getGsOrderCreateDateEnd() != null && !bean.getGsOrderCreateDateEnd().equals(""))
			result.append(" and c.GS_ORDER_CREATE_DATE <= '"+bean.getGsOrderCreateDateEnd()+" 23:59:59' ");
		result.append("  order by c.GS_ORDER_CREATE_DATE desc");
		return result.toString();
	}

	public int getOrderDetailListCount(GSOrderDetailQueryBean bean) throws Exception{
        String sql="select count(*) from ( "+this.getOrderDetailListSql(bean)+")";
        Object[] tobj={};
        int count=this.queryRowNum(sql, tobj);
        return count;
	}
}
